ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
activityManager.killBackgroundProcesses(getPackageName()); //关闭了所有Activity
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
在AndroidManifest.xml 加上
<!-- 关闭进程 --><uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>

本文详细介绍了如何在Android应用中利用ActivityManager接口强制重启应用并清除所有后台进程,确保应用的流畅运行。通过在AndroidManifest.xml中申请特定权限,开发者能够实现这一功能,为用户提供更稳定、高效的使用体验。
725

被折叠的 条评论
为什么被折叠?



