Open Baldur008 opened 2 years ago
enableBackgroundExecution requires the initialization to be finished. In the emulator, the initialization is presumably fast enough to be finished by chance. You should probably use await:
await FlutterBackground.initialize();
await FlutterBackground.enableBackgroundExecution();
If you need to do it in a non-async function, you can also do the following:
FlutterBackground.initialize().then((success) => FlutterBackground.enableBackgroundExecution());
Same issue for me. Working fine with emulator. I see that the await are done, but the app code is not running I am using:
const androidConfig = FlutterBackgroundAndroidConfig(
notificationTitle: "App name",
notificationText: "App is storing your location even when running in background",
notificationImportance: AndroidNotificationImportance.Max,
notificationIcon: AndroidResource(name: 'background_icon', defType: 'drawable'),
);
await FlutterBackground.initialize(androidConfig: androidConfig);
await FlutterBackground.enableBackgroundExecution();
The problem was in my real device configuration! I allowed my app to use location all the time, and it started working in the background too!
There's definitely an issue on real devices. You have to initialise the configuration twice in order for it to work.
same happened to me, on emulator works but on real devices throws
java.lang.RuntimeException: Unable to start service de.julianassmann.flutter_background.IsolateHolderService@8ca558 with Intent { act=START cmp=com.imvaswms.invaswmsdm/de.julianassmann.flutter_background.IsolateHolderService }: java.lang.IllegalArgumentException
Unable to start service Intent { act=START cmp=com.deskbtm.nitmgpt/de.julianassmann.flutter_background.IsolateHolderService } U=0: not found
Describe the bug It works in emulator but not in a real device
To Reproduce
Expected behavior I am calling both initialize and enablebackgroundexecution at the same time. It works on emulator but not in a real device
Smartphone:
Logs:
No Exception/Error Found.