安卓pressing后退按钮应该退出程序 [英] android pressing back button should exit the app

查看:168
本文介绍了安卓pressing后退按钮应该退出程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户presses在意向后退按钮,应用程序应该退出。我怎么能确保在应用程序退出时,后退按钮是pssed $ P $?

When a user presses the back button on an intent, the application should quit. How can I ensure the application quits when the back button is pressed?

推荐答案

后立即启动一个新的活动,使用 startActivity ,一定要叫完成(),这样当前的活动是不是堆放背后的新的。

Immediately after you start a new activity, using startActivity, make sure you call finish() so that the current activity is not stacked behind the new one.

修改 至于您的评论:

什么,你是在暗示是不是特别怎么Android应用程序流通常工作,以及如何将用户期望它的工作。你的什么可以的做,如果你真的想,是要确保每个 startActivity 导致这一活动,是一个 startActivityForResult 并有一个 onActivityResult 侦听器,检查出口code和气泡回来。您可以<一href="http://developer.android.com/intl/fr/reference/android/app/Activity.html#StartingActivities">read更多关于这里。基本上,使用的setResult 整理活​​动,设置你选择的退出code,如果你的父活动收到退出code,将其设置之前,中的的活动,并完成一个,等...

What you're suggesting is not particularly how the android app flow usually works, and how the users expect it to work. What you can do if you really want to, is to make sure that every startActivity leading up to that activity, is a startActivityForResult and has an onActivityResult listener that checks for an exit code, and bubbles that back. You can read more about that here. Basically, use setResult before finishing an activity, to set an exit code of your choice, and if your parent activity receives that exit code, you set it in that activity, and finish that one, etc...

这篇关于安卓pressing后退按钮应该退出程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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