Ghostwan Ghostwan - 1 year ago 80
Android Question

Android - Avoiding an activity to destroy, just stopping or pausing it when pushing the back button

I would like to pausing or putting the application on background when pressing the back button, I don't want the application to go through the destroy state. Things are when I override onKeyDown and when I force to pause or stop the application by using onPause, I have some issuees with the wakelock and application crash, but when I press home button I go through onPause method and I have no exception, it's weird!!

Answer Source

The answer is

public boolean onKeyDown(int keyCode, KeyEvent event)

    if (keyCode == KeyEvent.KEYCODE_BACK)
        return true; // return

    return false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download