How to move to specific ativity after pressing back in android key pad (android)
I want to specify in my code to move to a specific activity after pressing the back button on an android keypad. How can I accomplish this? Friends help me.
Now I found the solution with the help of our friends.
I found the solution to my problem. onBackPressed()
works after 1.6 version. For previous versions we need use
public boolean onKeyDown(int keyCode, KeyEvent event)
method
My code for this solved problem is
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.CUR_DEVELOPMENT
&& 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.
Intent i=new Intent(AgesWebViewIndex.this,TabCls.class);
i.putExtra("age", "agepage");
startActivity(i);
return;
}
in acitivy A -> startActivity(B);
in activity B -> startActivity(C);
in activity C -> start Activity(D);
in activity D -> go back to B or A other than C
if this is what you want... simply call finish(); after calling startActivity();
in activity A -> startActivity(B);
in activity B -> startActivity(C); finish();
in activity C -> startActivity(D); finish();
here if you press back button, you'll go directly back to activity A
hope i'm on the right track :p
If I get your point, you may want to capture the "on-Back button clicked" event and then start your desired activity inside that.
@Override public void onBackPressed() {
// do something on back. return;
}
For more info, please take a look at: http://android-developers.blogspot.com/2009/12/back-and-other-hard-keys-three-stories.html
精彩评论