Android的ActivityManager类是Android系统中的一个重要管理类,负责管理应用程序的Activity。下面是一些常见的ActivityManager使用案例:
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);
finish();
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningTaskInfo> runningTasks = activityManager.getRunningTasks(1);
String currentActivity = runningTasks.get(0).topActivity.getClassName();
Log.d(TAG, "Current Activity: " + currentActivity);
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
activityManager.killBackgroundProcesses("com.example.app");
ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
List<ActivityManager.RunningAppProcessInfo> runningAppProcesses = activityManager.getRunningAppProcesses();
for (ActivityManager.RunningAppProcessInfo processInfo : runningAppProcesses) {
Log.d(TAG, "Process Name: " + processInfo.processName);
}
总结:
ActivityManager是Android系统中重要的管理类,可以通过它来启动、销毁、获取当前运行的Activity和应用程序进程等操作。根据具体的需求,可以灵活运用ActivityManager来管理Android应用程序。