Search code examples
androidandroid-activityalarmmanagerandroid-package-managers

Android: Can I know if an application is running using AlarmMager


Is there any possible solution of knowing that some application is running in foreground using AlarmManager ?

Basically my question is that there is an argument importance associated with each process like procInfos.get(i).importance==100 in android, if this variable is 100 than it means that, that application's main activity is foregrounded at the moment and if its value is 400 than it means its in the background.. So my question is can I know the change of value for this variable for any specific application using AlarmManager in android ?


Solution

  • in android, if this variable is 100 than it means that, that application's main activity is foregrounded at the moment and if its value is 400 than it means its in the background

    A process can have foreground priority either by having a foreground activity or by having a foreground service (via startForeground()). AFAIK, both will have IMPORTANCE_FOREGROUND.

    So my question is can I know the change of value for this variable for any specific application using AlarmManager in android ?

    Well, AlarmManager can certainly get the running process information, if that's what you mean. However, the running process information is merely a snapshot of what the state was at the time you requested the information -- it is eminently possible that the process importance will have changed since that time, even if it was just a millisecond ago.