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???
+3
A:
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();
Pentium10
2010-07-28 09:55:37
I use this code to call the screen2 .How to finish the first screen here.I am new to android so please ....Intent i=new Intent(screen1.this,screen2.class);startActivity(i);
RMK
2010-07-28 09:59:25
I've edited my question
Pentium10
2010-07-28 10:00:53
Thank you for your Help.It works
RMK
2010-07-28 10:29:09
A:
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;
}
Donal Rafferty
2010-07-28 09:55:57