Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override Android Back Button

A little info as to why I am attempting to do this: I am using ActivityGroups to open an activity from a tabHost activity and have that new activity stay under the tabs. That part i've got. But when in that new activity, if I use the back button it takes me right out of the tabs activity so I have to click a few times to get back to where I was.

Is there a way to set the back button to go to a specific activity rather than killing the current activity window?

like image 960
ryandlf Avatar asked Sep 26 '11 03:09

ryandlf


1 Answers

I believe you should be able to do something like this:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        // start new Activity here
    }
    return super.onKeyDown(keyCode, event);
}

But overriding the expected functionality of the back button is not advisable.

like image 80
Tyler Treat Avatar answered Oct 14 '22 15:10

Tyler Treat