我正在使用此代码在 1 秒后强制关闭我的应用程序。但问题是它关闭后会自己重启!我怎样才能让它永久关闭?
private fun endApp() {
val handler = Handler()
handler.postDelayed({ Process.sendSignal(Process.myPid(), Process.SIGNAL_KILL) }, 1000)
}
最佳答案
使用此方法强制退出您的应用:
fun exitApp() {
moveTaskToBack(true);
exitProcess(0)
}
exitProcess(status: Int): Terminates the currently running process.
moveTaskToBack (boolean nonRoot) Move the task containing this activity to the back of the activity stack. The activity's order within the task is unchanged.
或
finishAffinity(): Finish this activity as well as all activities immediately below it in the current task that have the same affinity. This is typically used when an application can be launched on to another task (such as from an ACTION_VIEW of a content type it understands) and the user has used the up navigation to switch out of the current task and in to its own task. In this case, if the user has navigated down into any other activities of the second application, all of those should be removed from the original task as part of the task switch.
fun exitApp() {
finishAffinity()
}
关于java - 不重新启动就不能强制关闭应用程序吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63385441/