I’m looking for a way on Android to know when my app is active (running, viewable) and deactivated.
I know I can use the onStart methods but there’s a problem with that:
if I switch to another activity, i don’t want the app to think “I’m deactivated and hey, activated again!” not even for a short period.
Why I want to do this:
I need to subscribe to a server when the app is active and unsubscribe when the users goes to another app, this can happen in every activity of the app.
So when the user switches to another activity of my app, the app must remain subscribed to the server.
Are there some kind of broadcast I can catch just like the wifi status? Or do I really have to put some logic in every activity (a super class is not always possible)
Create a class that extends Application and monitor the status there.