Android - Check application process State

时间秒杀一切 提交于 2019-12-01 10:45:52

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

exception01

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();
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!