判断程序在后台运行还是前台
2016-09-02 15:06
537 查看
public static boolean isBackground(Context context) { ActivityManager activityManager = (ActivityManager) context .getSystemService(Context.ACTIVITY_SERVICE); List<ActivityManager.RunningAppProcessInfo> appProcesses = activityManager .getRunningAppProcesses(); for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) { if (appProcess.processName.equals(context.getPackageName())) { /* * BACKGROUND=400 EMPTY=500 FOREGROUND=100 GONE=1000 * PERCEPTIBLE=130 SERVICE=300 ISIBLE=200 */ Log.i("xx", "此appimportace =" + appProcess.importance + ",context.getClass().getName()=" + context.getClass().getName()); if (appProcess.importance != ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) { Log.i("xx", "处于后台" + appProcess.processName); PreferenceHelper.write(context, "handlerLog", "handlerLog", "true"); return true; } else { Log.i("xx", "处于前台" + appProcess.processName); return false; } } } return false; }
相关文章推荐
- 判断程序是前台运行还是后台运行的方法?
- Android之判断程序在前台运行还是后台运行
- Android如何判断程序是在前台还是在后台运行
- Android 判断程序在前台运行还是后台运行
- 安卓判断APP是运行在前台还是后台
- Android 判断app是否在前台还是在后台运行
- Android 判断app是否在前台还是在后台运行
- Android 判断app是否在前台还是在后台运行
- Android 判断app是否在前台还是在后台运行
- iOS判断程序在前台还是后台
- Android 判断程序在前台还是后台
- Android判断App前台运行还是后台运行(运行状态)
- Android判断App前台运行还是后台运行(运行状态)
- 判断APP是运行在前台还是后台
- android 判断应用程序在前台还是在后台运行
- 判断程序在前台还是退到后台的方法
- (4.1.2.6)Android 判断app是否在前台还是在后台运行
- Android判断程序是前台还是后台
- Android 判断应用运行的前台还是后台
- Android 判断app是否在前台还是在后台运行