I have override the OnBackPressed
function inside my activity, but it's not being called. On other activities it's working fine.
Here is my method:
@Override
public void onBackPressed() {
Log.e("back",""+1);
UserPage.getstate().finish();
Intent i=new Intent(CreateGroup.this,UserPage.class);
i.putExtra("title11","dd");
startActivity(i);
finish();
}
This method is not being called, and the default OnBackPresssed
is called every time i press the back button.
The onBackPressed() is a default action called from onKeyDown() in API < 5 and a default action called from onKeyUp() from API level 5 and up. If onKeyUp() does not call super. onKeyUp() , onBackPressed() will not be called.
An activity provides the window in which the app draws its UI. This window typically fills the screen, but may be smaller than the screen and float on top of other windows. Generally, one activity implements one screen in an app.
Try this code
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Log.e("back",""+1);
UserPage.getstate().finish();
Intent i=new Intent(CreateGroup.this,UserPage.class);
i.putExtra("title11","dd");
startActivity(i);
finish();
}
return true;
}
Had a similar issue. The problem for me was in my override of onKeyDown() hiding the KEYCODE_BACK keydown events.
Have you tried this? ,
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
// do something on back pressed.
return true;
}
return super.onKeyDown(keyCode, event);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With