请参见用户执行的Android最近的任务 [英] See Android recent task executed by the user
问题描述
我就喜欢看我的Android手机,最近的任务。我试图从互联网上一些code,但非他们的正常工作。我只是想获得用户执行的最后一个应用程序的PID和名称。例如,如果我执行的计算器应用程序,并在那之后,我做,这个应用程序建议立即进行删除能告诉我,像近期任务的应用程序:你最后执行的应用程序是计算器和PID为2222
I would like to watch the recent task of my android phone. I was trying some code from internet but non of them work properly. I just want to get the PID and Name of the last application executed by the user. For example, if I execute the calculator application and after that the recent task application that I made, this application shoul be able to tell me something like: "the last application you've executed is 'calculator' and the PID is '2222'".
我被检查的Android开发者网页一些code,这是我发现了什么,但我不知道如何实现为Android。
I was checking on Android developers web page for some code and this is what I found, but I don't know how to implement for Android.
ActivityManager.RecentTaskInfo
信息您可以检索有关用户最近一次启动或访问任务。
ActivityManager.RecentTaskInfo
Information you can retrieve about tasks that the user has most recently started or visited.
ActivityManager.RunningServiceInfo
,可以检索有关当前系统中运行的特定服务信息。
ActivityManager.RunningServiceInfo
Information you can retrieve about a particular Service that is currently running in the system.
任何建议,
最好的问候
ActivityManager.RunningTaskInfo
信息,可以检索有关系统当前跑一个特定的任务。
ActivityManager.RunningTaskInfo
Information you can retrieve about a particular task that is currently "running" in the system.
推荐答案
下面是我的解决办法:
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final List<RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);
for (int i = 0; i < recentTasks.size(); i++)
{
Log.d("Executed app", "Application executed : " +recentTasks.get(i).baseActivity.toShortString()+ "\t\t ID: "+recentTasks.get(i).id+"");
}
注意!!最后的ID是不是进程的PID!如果您想获得该进程的PID我用下面的命令:
Be careful!!The last ID is not the PID of the process!! If you want to get the PID of the process I used the following command :
mLogcatProc = Runtime.getRuntime().exec(new String[] {"ps"});
读取结果发现该应用程序的名称,然后拆分获得PID过程。
Read the result finding the application name and then split to obtain PID process.
这篇关于请参见用户执行的Android最近的任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!