开发者

Android - Check application process State

开发者 https://www.devze.com 2023-02-14 09:38 出处:网络
How can I check the state (pause/running/suspended) of a particular process running on the And开发者_StackOverflow中文版roid device programmatically? I want to include this logic within my application

How can I check the state (pause/running/suspended) of a particular process running on the And开发者_StackOverflow中文版roid 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.


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


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();
}
0

精彩评论

暂无评论...
验证码 换一张
取 消