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;
}
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