0

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 ?

Saaram
  • 337
  • 3
  • 7
  • 29
  • What does the `AlarmManager` have to do with currently running applications? I'm not clear on what your question is actually asking. – kabuko Dec 12 '12 at 20:56
  • `AlarmManager` lets our activity know that any specific action has occurred ! right ? So I just want to know the change of this variable's value from 400 to 100 immediately when it gets changed using `AlarmManager`. Is it possible ? – Saaram Dec 12 '12 at 20:59
  • "AlarmManager lets our activity know that any specific action has occurred ! right ?" No. Read the [documentation](http://developer.android.com/reference/android/app/AlarmManager.html). – kabuko Dec 12 '12 at 21:02
  • Does alarmManager gets buzzed when 12:00 am occurs on the clock ? just a random question – Saaram Dec 12 '12 at 21:06

1 Answers1

1

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • This is the problem.. I am developing an application in which a service is running at the background which all the times checks for that application that if its foreground so here the big problem is the battery time and efficiency.. So, my question is if alarmManager can help me know this change in the `importance` variable than I wont be having to use the service which could certainly save battery – Saaram Dec 12 '12 at 21:03
  • @Saaram: The best answer is for you to not monitor the `importance` variable. It is impossible to "know this change in the `importance` variable" except by *continuously* requesting process information, which will hammer the device. I suggest that you find some other solution to whatever problem you are trying to solve by use of `importance`. – CommonsWare Dec 12 '12 at 21:10