prevent application from destroying on back button press

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

prevent application from destroying on back button press

Postby jjaaxx44 » Wed Feb 25, 2009 6:43 am

hey frends,
i am designing a game using single view.
when i press back button due to life cycle of android ie onPause()->onStop()->onDestroy();
my application exits.
i want it to go back on previous screen or to open menu, so is der any way...?? :(
thanx in advance
jjaaxx44
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sat Jan 31, 2009 4:44 am

Top

Postby timhoeck » Wed Feb 25, 2009 7:12 am

You can use dispatchKeyEvent to override keys like the Back button:

Code: Select all
public boolean dispatchKeyEvent(KeyEvent event) {
       if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
          switch (event.getAction()) {
          case KeyEvent.ACTION_DOWN:
             Log.i(TAG, "Back was pressed");
             break;
          case KeyEvent.ACTION_UP:
             Log.i(TAG, "Back key was released");
             break;
          }
       }
       return true;
    }
timhoeck
Junior Developer
Junior Developer
 
Posts: 22
Joined: Fri Jan 16, 2009 4:41 pm

Postby jjaaxx44 » Wed Feb 25, 2009 7:52 am

thanks dude....its working fine.....jst hace 2 change my logic a bit....
thanx v.much
jjaaxx44
Junior Developer
Junior Developer
 
Posts: 10
Joined: Sat Jan 31, 2009 4:44 am

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 2 guests