Implement onKeyDown to handle the BACK key yourself.

On Sun, Jan 11, 2009 at 6:36 AM, tmat <[email protected]> wrote:

>
> Hi,
> I'd like to control when user click back button and show him some YES/
> NO dialog after that. Depends what he select I will close activity or
> leave one. Any ideas how I can do this one ?
>
> I've tried to put dialog initialization into onPause() method but
> obviously it doesn't work based on Activity Lifecycle so this doesn't
> work:
>
>  @Override
>    protected Dialog onCreateDialog(int id) {
>        return new AlertDialog.Builder(TimeCard.this).setIcon
> (R.drawable.alert_dialog_icon).setTitle(
>                R.string.alert_dialog_msg).setPositiveButton
> (R.string.alert_dialog_ok,
>                new DialogInterface.OnClickListener() {
>                    public void onClick(DialogInterface dialog, int
> whichButton) {
>                        onHandleLogout();
>                    }
>                }).setNegativeButton(R.string.alert_dialog_cancel, new
> DialogInterface.OnClickListener() {
>            public void onClick(DialogInterface dialog, int
> whichButton) {
>
>                /* User clicked Cancel so do some stuff */
>            }
>        }).create();
>    }
>
>    @Override
>    protected void onPause() {
>        showDialog(0);
>        super.onPause();
>    }
>
>
> Any other suggestions ?
>
> >
>


-- 
Dianne Hackborn
Android framework engineer
[email protected]

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them.

--~--~---------~--~----~------------~-------~--~----~
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