0

I have an application that has a Main menu (MainMenu.java) which starts an activity (ActivityBlah) on a menu button press:

public void onClick(View v) {
 switch (v.getId()) {
 case R.id.AcitivityBlahButton:
   startActivity(new Intent(MainMenu.this, AcitivityBlah.class));
   break;
 }
}

ActivityBlah.java should not call onDestroy, rather call onResume on back button press and this button should also lead to the main menu.

Tried this:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event)  
{
      if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0)
      {
        this.moveTaskToBack(true);
           return true;
      }
      return super.onKeyDown(keyCode, event);
}

And this:

@Override
public void onBackPressed() {
  onPause();
  startActivity(new Intent(ActivityBlah.this, MainMenu.class));
}

..and few more suggestions on this website - none of them worked.

1) As soon as I press back button when ActivityBlah is on foreground, it closes the application and I'm shown the phone's home-screen. How can I ensure I go back to MainMenu in this case?

2) Once I succeed in 1), how do I ensure that StartActivity in MainMenu.java does not "create" ActivityBlah, rather "resume" it as I would have "paused" it by pressing back button rather than "destroyed" it?

attiwari
  • 1
  • 2
  • 2
    So basically you ask us how to break the whole back button behavior on your app? – Waza_Be Jan 08 '13 at 18:05
  • if your stack is `MainMenu -> Blah` then back should take you back to the main menu anyway! – IAmGroot Jan 08 '13 at 18:14
  • Waza_Be - well that's you interpretation! Doomsknight: Problem is - it doesn't take me back to main menu...I'm straight back to the home page. – attiwari Jan 09 '13 at 10:16

0 Answers0