NavinC
NavinC

Reputation: 243

Android - Check application process State

How can I check the state (pause/running/suspended) of a particular process running on the Android device programmatically? I want to include this logic within my application.

Using ActivityManager, I am able to retrieve a list of all processes running on the device, but it doesn't show me any process state information. Any idea on how I can retrieve this information?

Thanks in Advance.

Upvotes: 3

Views: 8920

Answers (2)

iamtheexp01
iamtheexp01

Reputation: 3466

You can follow the activity lifecycle. Put your logic in each state. I don't know if there is a get state in activity.

public class Activity extends ApplicationContext {
     protected void onCreate(Bundle savedInstanceState);
     protected void onStart();
     protected void onRestart();
     protected void onResume();
     protected void onPause();
     protected void onStop();
     protected void onDestroy();
}

Upvotes: 0

NavinC
NavinC

Reputation: 243

I was wrong when I mentioned in the question that there is no process state information in the list of processes retrived using ActivityManager.

 ActivityManager am = (ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
   List<RunningAppProcessInfo> list2= am.getRunningAppProcesses();
   for (RunningAppProcessInfo ti : list2) {

       Log.i("IMPORTANCE CODE",String.valueOf(ti.importance));
  }

ti.importance retrives a constant value which describes whether the process is running FOREGROUND, BACKGROUND, Empty of code etc...

More information can be found at the following location:

http://developer.android.com/reference/android/app/ActivityManager.RunningAppProcessInfo.html

Thanks, Navin

Upvotes: 2

Related Questions