Android的 - 检查应用程序状态 [英] Android - Check application process State
问题描述
我如何检查Android设备编程上运行的特定进程的状态(暂停/运行/暂停)?我想包括在我的应用程序这样的逻辑。
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.
使用 ActivityManager
,我可以检索设备上运行的所有进程的列表,但它并没有告诉我任何进程状态信息。我如何能获取这些信息你知道吗?
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?
在此先感谢。
推荐答案
我错了,当我在问题中提到,在进程列表中retrived使用ActivityManager没有过程的状态信息。
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一个恒定值,它描述的进程是否正在运行前景,背景,空的code等...
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
谢谢, 纳文
这篇关于Android的 - 检查应用程序状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!