android 如何判断程序是否在前台运行
16lz
2021-01-23
protected static boolean isTopActivity(Activity activity){ String packageName = "xxxxx"; ActivityManager activityManager = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE); List<RunningTaskInfo> tasksInfo = activityManager.getRunningTasks(1); if(tasksInfo.size() > 0){ System.out.println("---------------包名-----------"+tasksInfo.get(0).topActivity.getPackageName()); //应用程序位于堆栈的顶层 if(packageName.equals(tasksInfo.get(0).topActivity.getPackageName())){ return true; } } return false; }
更多相关文章
- Android彻底退出应用程序
- Android 应用程序基础(Application Fundamentals)----Application
- 应用程序组件之APP基础(转官方)
- Android Training - 建立你的第一个应用程序
- Android开发指南 ──应用程序基础
- android 跨应用程序广播发送接受