Is there a way to determine whether the app is running or not?
Hi! Is there a way to determine whether the app is running right now in the foreground or not during an execution of the background task?
I need to get some jobs done only when an user is not using the app right now. I tried to use requiresDeviceIdle: true, but with this option my background tasks don't fire at all.
I need this feature too. I used Workmanager with Google Mobile Ads basic example code. When callbackDispatcher is called, the app is killed or the UI is broken. Can't callbackDispatcher be called only when the app is closed? I need to use both Workmanager and Google Mobile Ads package.
You can try to use WidgetsBinding.instance.lifecycleState to determine the widgets state, which hopefully is reflected.
You can also try this plugin https://github.com/ened/flutter_native_app_state_plugin but please note this is not implemented on Android yet (it should be straightforward to use the lifecycle plugins).
It seems that the lifecycleState does in fact not reflect whether the app is currently running or not.
I assume because we are on different isolates and have different widget bindings.
No matter, it seems that my workmanager callback always get detached, regardless of there being an instance of the app running in foreground or not.
@clragon in that case please try the native app state plug-in above and extend it - prs welcome
any update?