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?