tags:

views:

38

answers:

2

When back key is pressed, current activity goes background. I'd like to show a popup and let user choose really close this activity, before current activity go background. I tried to override onPause(), but it's called after activity goes back.

Please somebody explains me how to do that?

A: 

Did you try to override onPause() ?

In my case when I hit the back button it first call onPause() before calling onStop().

There is a good video explaining an application lifecycle processus :

http://blip.tv/file/958450/

Spredzy
Thanks for replay.Yeah, I've tried onPause(), but failed.I have to show a kind of modal dialog, but I have no idea how to do that.
backspace7
if not you have a method onBackPressed() that let you do what ever you want when the back button is pressed.So you overload this function and inside you implement your modal dialog.
Spredzy
Actually, I want to hook just one back key pressing which makes activity go background().
backspace7
A: 

You can override the onKeyDown method of the Activity:

public boolean onKeyDown(int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_BACK){
            //Show the dialog and get the response
        }

//Do a if here with your variable returned from the dialog      
return super.onKeyDown(keyCode, event);
    }
YaW
Thank you, that's exactly what I want.
backspace7