/** * 判断一个Activity是否正在运行 * @param pkg * @param context * @return */ public static boolean isClsRunning(String pkg,Context context) { ActivityManager am = (ActivityManager)context.getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningTaskInfo> list = am.getRunningTasks(100); for (ActivityManager.RunningTaskInfo info : list) { Log.d("HLD",info.topActivity.getPackageName()+", "+info.baseActivity.getClassName()+", "+info.topActivity.getClassName()); if (info.topActivity.getPackageName().equals(pkg) && info.baseActivity.getPackageName().equals(pkg)) { //find it, break return true; } } return false; } 需要权限:<uses-permission android:name="android.permission.GET_TASKS" />
判断app是否启动
最新推荐文章于 2021-11-08 13:28:08 发布