barisatbas
barisatbas

Reputation: 564

Android Check Application Status

I have a question about Android application status. I want to know that am I able to check whether application is alive or dead, visible or on background. I need to make a decision according to application status in my broadcast receiver.

Thanks in advance..

Upvotes: 2

Views: 5706

Answers (3)

CommonsWare
CommonsWare

Reputation: 1007584

You determine if your "application" is "alive" by seeing if the data you loaded in your "start up process" exists. If it does, use it. If it does not, run the "start up process".

Upvotes: 2

inazaruk
inazaruk

Reputation: 74790

Basically, when your receive broadcast your application is guaranteed to run. That's because broadcast can not be received without application process started first. And if there were no components active (like activities) when broadcast is sent, then application process is started for the sole purpose of processing this broadcast.

As for the other part, detecting if any Activity is currently active and/or visible - I haven't seen any API calls for this. There are might be some workaround (like manually keeping the counter in a singleton), but as far as I know there is no direct support for this. Though I might be wrong.

Upvotes: 1

mastDrinkNimbuPani
mastDrinkNimbuPani

Reputation: 1249

Within Android, it is standard practise to track 'changes' to the various states. You can read more about this here. Within the specific lifecycle related methods, you can perform specific actions as deemed appropriate.

Upvotes: 1

Related Questions