我想要关闭安卓应用
int id= android.os.Process.myPid();
android.os.Process.killProcess(id);
此代码终止进程。
最佳答案
如果每次用户从主屏幕启动应用程序或从最近使用的应用程序列表返回时,您总是希望您的应用程序从根 Activity(第一个 Activity)开始,则将其添加到<activity>
根 Activity 的标签:
android:clearTaskOnLaunch="true"
但是,如果您只想完成当前任务中的所有 Activity ,您可以执行以下操作:
Intent = new Intent(this, MyRootActivity.class); // MyRootActivity should be the name of your root (launcher) activity
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("exit", "true"); // This tells MyRootActivity that you want to exit
这将导致任务中的所有 Activity 完成,并创建一个新实例 MyRootActivity
.在 MyRootActivity.onCreate()
执行以下操作:
if (getIntent().hasExtra("exit")) {
finish(); // We want to exit the application, so just finish this activity now
}
关于android - 如何关闭 Android 中的所有 Activity 并从任务管理器中关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14052849/