干净地退出应用程序
我想放置一个菜单按钮“退出”以便让用户离开应用程序。 我读到我可以使用 moveTaskToBack。这可行,但我希望用户通过家庭活动而不是他离开的活动重新进入应用程序。
您有什么建议吗?
I want to put a menu button 'Exit' in order to let user to leave the App.
I read that I could use moveTaskToBack. This works but I would like the user to re-enter in the App through Home Activity and not the Activity he left.
Do you have any suggestion?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
公共无效终止()
{
Log.i("myid","终止!!");
super.onDestroy();
this.finish();
}
并看看这个很好的答案。
还可以查看此处..
public void terminate()
{
Log.i("myid","terminated!!");
super.onDestroy();
this.finish();
}
and have a look at this fine answer.
and also have a look at here..
对于我的退出按钮上的 Android 应用程序,我使用调用 finish();也许这就是您正在寻找的?
For my android apps on my exit button I use a call to finish(); Maybe this is what you are looking for?
好吧,罗宾汉,
我对您的代码的理解是,当用户按下退出按钮时,它应该离开应用程序,当您重新启动应用程序时,它应该从应用程序离开的上一个活动恢复。
实际上,当我们按下Home按钮时,这是相同的行为。因此,您只需要创建在退出单击时按下主页按钮的事件。
=========================================
好的,我不知道以下解决方案是否好但。如果您想终止整个应用程序并从家庭活动中恢复。您可以将 launchMode 放入 menifeast 文件中的 sigleinstance 中以进行其他活动。
或者
您可以在按下退出按钮递归退出活动时设置静态标志。
Well robin hood,
my understanding to your code is that, when user press Exit button it should leave app and when you restart app it should resume from previous activity where application left.
Actually it is same behavior when we press Home button. So you just need to create event home button pressed on exit click.
=======================================
Ok, I don't know following solution is good but. If you want to terminate entire app and resume from home activity. You can put launchMode to sigleinstance in menifeast file for other activities.
or
You can set a static flag when exit button pressed recursively exit the activities.
干净的退出代码是:
看起来有点奇怪但可行
Clean exit code is:
It's a bit odd-looking but workable