I have an app that needs to do some background cleaning job when it goes idle, it uses a service that's always running in the background and a BroadcastReceiver
registered on ACTION_SCREEN_OFF
and ACTION_SCREEN_ON
which detects when the screen goes off and runs the background worker, also I'm using the onPause
method in my main activity to signal the service to start the background worker.
The problem I'm having is that when the screen switches off the onPause
is been called first then the BroadcastReceived
detects the screen off action, so the background worker gets called twice.
Is it possible to find in the onPause
method if the app is minimized and the screen is still on?