如何关闭我的应用程序/退出键? [英] How i can close/exit button on my app?

查看:167
本文介绍了如何关闭我的应用程序/退出键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个按钮,这个code关闭我的应用程序:

i have a button to close my app with this code:

完成();

问题是,这个按钮不会退出我的应用程序......它只是关闭我的应用程序的previous意图(窗口)......

the problem is that this button doesn't exit of my app... it simply closes the current intent ant returns to the previous intent (window) of my app....

我怎么可以做一个真正的退出/关闭按钮?

how i can do a real exit/close button?

我trye​​d这一点:

i tryed with this:

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

但它没有工作,因为当我回头到我的应用程序,该应用程序自带的最后在应用程序的第一个窗口打开的窗口,而不是,我怎么能做到这一点?我需要,当我重新打开我的应用程序,它开始我的应用程序的第一个窗口

but it doesn't works, because when i turn back into my app, the app comes in the last opened window, and not in the first window of the app, how i can do that? i need that when i re-open my app it starts on the first window of my app

推荐答案

如果你真的想你的应用程序就不行了。你可以启动每个意图与startActivityForResult()。那么每个完成前()设置的结果发回。每个家长活动,您可以覆盖onActivityResult()来测试结果是否收到意味着应用程序需要结束。如果是的话,你可以调用另一组的结果,完成()。在所有活动中重复这一点,你会发现你的应用程序完全终止

If you really want your app to die. You could initiate each intent with startActivityForResult(). then before each finish() set the result to send back. in each parent activity you can override onActivityResult() to test whether the result received means the application needs to end. if so you can call another set result and finish(). repeat this in all activities and you will find that your application terminates entirely.

顺便说一句,我从内存中写入这一点。函数名可能不准确。

Incidentally I'm writing this from memory. function names may not be exact.

希望有所帮助。

P.S。重读你的要求。你可以随时停止终点循环在你的第一个活动。

p.s. re-read your requirements. you can always stop the finish loop at your first activity.

这篇关于如何关闭我的应用程序/退出键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆