Reputation:
I wanted to keep the activity alive, when the user presses back button of the android device. From the documentation, the back press will call onPause, onStop and finaaly to onDestroy.
Is it possible to keep my activity alive in Stack, when the user presses back button.
Upvotes: 0
Views: 292
Reputation: 653
override a method called onBackPresses. and remove or comment super.onBackPressed();
For E.G.-
public void onBackPressed() {
// TODO Auto-generated method stub
//super.onBackPressed();
}
Upvotes: 0
Reputation: 687
You should to override the onBackPressed method and do nothing.
@Override
public void onBackPressed() {
}
Upvotes: 1
Reputation: 14810
Try this one..Worked for me..
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Back?
if (keyCode == KeyEvent.KEYCODE_BACK) {
// Back
moveTaskToBack(true);
return true;
}
else {
// Return
return super.onKeyDown(keyCode, event);
}
}
OR try this
public void onBackPressed() {
// TODO Auto-generated method stub
moveTaskToBack(true);
}
Not sure about the 2nd method as i have not tried it..give it a try..
Upvotes: 2
Reputation: 2535
Just override below method:
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
}
Upvotes: 0