Background:
I have a background service with a timer. It opens up a new activity when 20 seconds are over.
Currently, my app is using componentCallbacks2
to detect when the user has pressed the home screen, or has left the app, and on detection, I stop the timer, so that the activity doesn't get called.
But, for some reason, componentCallBacks2
does not get called when the user just closes out of the app:
Here you can see the user closing an app. For some reason, my app doesn't stop its processes when the app is closed. And, the timer continues to run. This results in the activity popping up on the users screen after 20 seconds, even though the user isn't in the app.
How can I detect if the app has been closed so that I can stop the timer? I have read on this topic in many other sources, and those sources just say to use the onStop
method. I can't do that, because the onStop
gets called whenever there is a change in activities
So, where should I stop the timer?