我在一个Android APP里面给notification设置了个按钮,希望点击之后能够退出APP,停止一切用到的服务(例如:科大讯飞的语音识别服务,自己启动的一些service,打开过的activity)。
我用了以下两种方法
System.exit(0)
Process.killProcess(Process.myPid())
但是都不能完全退出APP,可以杀死service,也可以停止语音识别等服务,但是没有退出activity,按下home键把应用后台了之后点击那个停止按钮之后打开APP没有从头开始启动第一次打开的launch页面,而是直接打开了刚刚后台了的时候开着的activity。
我该怎么准确退出这个APP回到那种什么都没开过的那种初始状态。
谢谢大神们 !
You can control all activities in your own queue. The code is as follows:
Add in the onCreate method in your BaseActivity:
Then call where you need
Hope it helps you
Listen to the open activities in the application and kill all activities after clicking the button
It seems that no one has answered, so I will post my own solution.
Still don’t know how to completely exit the APP, so I first clear the activity stack and then kill the process.
Define an Activity queue, add each activity when it is created, and provide a static method to finish all activities in the queue