判断程序是否还在手机中存活
返回的是boolean值
public boolean isAppaLive(Context context ,String str) {
ActivityManager am = (ActivityManager) context
.getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> list = am.getRunningTasks(100);
boolean isAppRunning = false;
//String MY_PKG_NAME = "你的包名";
for (RunningTaskInfo info : list) {
if (info.topActivity.getPackageName().equals(str)//如果想要手动输入的话可以str换成<span style="font-family: Arial, Helvetica, sans-serif;">MY_PKG_NAME,下面相同</span>
|| info.baseActivity.getPackageName().equals(str)) {
isAppRunning = true;
Log.i(TAG, info.topActivity.getPackageName()
+ " info.baseActivity.getPackageName()="
+ info.baseActivity.getPackageName());
break;
}
}
return isAppRunning;
}