查看用户最近执行的Android任务
我想查看我的 Android 手机最近的任务。我正在尝试来自互联网的一些代码,但它们都不能正常工作。我只想获取用户最后执行的应用程序的PID和名称。例如,如果我执行计算器应用程序,然后执行我创建的最近任务应用程序,则该应用程序应该能够告诉我类似以下内容:“您执行的最后一个应用程序是‘计算器’,PID 是‘2222’ ”。
我在 Android 开发人员网页上检查了一些代码,这就是我发现的,但我不知道如何在 Android 上实现。
ActivityManager.RecentTaskInfo
您可以检索有关用户最近启动或访问的任务的信息。
ActivityManager.RunningServiceInfo
您可以检索有关系统中当前运行的特定服务的信息。
任何建议,
最好的问候
ActivityManager.RunningTaskInfo
您可以检索有关系统中当前“运行”的特定任务的信息。
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'".
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
Information you can retrieve about tasks that the user has most recently started or visited.
ActivityManager.RunningServiceInfo
Information you can retrieve about a particular Service that is currently running in the system.
any suggestion,
Best regards
ActivityManager.RunningTaskInfo
Information you can retrieve about a particular task that is currently "running" in the system.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
getRunningTasks
RunningTaskInfo
getRunningTasks
RunningTaskInfo
这是我的解决方案:
小心!!最后一个ID不是进程的PID!如果你想获取进程的PID,我使用了以下命令:
读取结果找到应用程序名称,然后拆分以获得PID进程。
Here is my solution:
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 :
Read the result finding the application name and then split to obtain PID process.
我最近正在检查可用的服务,该服务也正在使用活动管理器。
可能只需将其更改为 getRecentTasks(int maxNum, int flags) 方法并根据您的需要修改以下内容!?
I was recently checking on available services which also was using the activity manager.
Probably just change this to the getRecentTasks(int maxNum, int flags) method and modify the below to your needs!?