You can override onBackPressed in your Activity. This is called when
the user presses the back button, before your Activity is finished by
the system. You could pop a dialog asking the user to confirm this
action, if they hit yes you call through to the super and the Activity
gets finished, if they hit no you do nothing and the Activity resumes
[I've never tried this, but AFAIK this should work]. Only problem is
this method is only available in Android 2.0+ [introduced in API Level
5].

Restarting the Activity in onStop sounds incredibly intrusive for your
user experience.

-Nick



On Apr 27, 12:22 am, Xiongzh <[email protected]> wrote:
> Some of my customers are accustomed to use the back button to go back
> to the previous activity. Some complained that they often navigate out
> of the application by pressing back button. I think it would be nice
> to customers if they can be warned.
>
> Thanks for your suggestion.
>
> How do think the approach I used?
>
> On Apr 27, 2:43 pm, Nicholas Albion <[email protected]> wrote:
>
>
>
>
>
> > My first thought was to suggest that you rethink if you really need to
> > do this - maybe your app isn't going to be as important to your users
> > as you may think.
>
> > But then, I been frustrated in the past by games which exit in the
> > middle of the game if you press too far right...
>
> > Maybe you should provide an option (which you'd only ever ask once):
> > "Always confirm before exiting"
>
> > > I can find some posts on how to warn user when the back button is
> > > pressed to 'quit' the application.
>
> > > The common answer is to catch the key down event by onKeyDown, or use
> > > startActivityForResult().
>
> > > My approach is to restart the activity in onStop().
> > > Is it a better choice?
>
> > > Please help to check if there's anything inappropriate.
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group 
> > athttp://groups.google.com/group/android-developers?hl=en
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]
> For more options, visit this group 
> athttp://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to