Reputation: 819
In my application i have two screen. Screen1 and screen2 . If i am in screen2 when i click the back button it shows the screen1. I need to close application at the time of clicking back button in the screen2 . How to do this???
Upvotes: 2
Views: 382
Reputation: 207863
Probably you start screen2 from screen1 via an Intent.
After you call startActivity(screen2) you should close screen1, via the finish()
call.
Something like:
Intent screen2=new Intent(Screen1.this,Screen2.class);
startActivity(screen2);
finish();
Upvotes: 5
Reputation: 19826
From http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html :
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.ECLAIR
&& keyCode == KeyEvent.KEYCODE_BACK
&& event.getRepeatCount() == 0) {
// Take care of calling this method on earlier versions of
// the platform where it doesn't exist.
onBackPressed();
}
return super.onKeyDown(keyCode, event);
}
@Override
public void onBackPressed() {
// This will be called either automatically for you on 2.0
// or later, or by the code above on earlier versions of the
// platform.
return;
}
Upvotes: 0