检查应用程序正在运行? [英] Checking App is running?

查看:133
本文介绍了检查应用程序正在运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能为一个服务检查以下


  1. 无论应用程序正在运行或不?

  2. 如果是的话,它应用的运行是背景或前景?请建议一些方法来做到这一点。


解决方案

您需要使用<一个href=\"http://developer.android.com/reference/android/app/ActivityManager.html#getRunningTasks%28int%29\"相对=nofollow> getRunningTasks ,以了解应用程序是否正在运行与否。

从文档:

公开名单getRunningTasks(INT MAXNUM)

为了以后

返回当前正在运行的任务列表,最近的是第一和旧的。

对于这个工作,你应该包括这在你的Andr​​oidManifest.xml

 &LT;使用许可权的android:NAME =android.permission.GET_TASKS/&GT;

和有关应用程序的运行背景/前景请参阅本<一个href=\"http://stackoverflow.com/questions/3667022/android-is-application-running-in-background\">LINK

Is it possible for a service to check the following

  1. Whether a App is running or not?
  2. If yes, is it App running is background or foreground? Please suggest some way to do it.

解决方案

You need to use getRunningTasks to know whether the app is running or not.

From the docs:

public List getRunningTasks (int maxNum)

Return a list of the tasks that are currently running, with the most recent being first and older ones after in order.

For this to work you should include this in your AndroidManifest.xml

<uses-permission android:name="android.permission.GET_TASKS" />

And regarding App running background/foreground refer this LINK

这篇关于检查应用程序正在运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆