gpt4 book ai didi

java - 不重新启动就不能强制关闭应用程序吗?

转载 作者:行者123 更新时间:2023-12-02 13:41:05 25 4
gpt4 key购买 nike

我正在使用此代码在 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 runningprocess.

moveTaskToBack (boolean nonRoot) Move the task containing thisactivity to the back of the activity stack. The activity's orderwithin the task is unchanged.

finishAffinity(): Finish this activity as well as all activitiesimmediately below it in the current task that have the same affinity.This is typically used when an application can be launched on toanother task (such as from an ACTION_VIEW of a content type itunderstands) and the user has used the up navigation to switch out ofthe current task and in to its own task. In this case, if the user hasnavigated down into any other activities of the second application,all of those should be removed from the original task as part of thetask switch.

fun exitApp() {
finishAffinity()
}

关于java - 不重新启动就不能强制关闭应用程序吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63385441/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com