flutter_workmanager icon indicating copy to clipboard operation
flutter_workmanager copied to clipboard

Is there a way to determine whether the app is running or not?

Open alexursul opened this issue 5 years ago • 5 comments

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.

alexursul avatar Oct 20 '21 14:10 alexursul

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.

devmoonho avatar Oct 24 '21 13:10 devmoonho

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).

ened avatar Oct 29 '21 09:10 ened

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 avatar Aug 15 '22 23:08 clragon

@clragon in that case please try the native app state plug-in above and extend it - prs welcome

ened avatar Aug 17 '22 19:08 ened

any update?

joharputr avatar Aug 10 '23 02:08 joharputr