Reputation: 8818
I have three activities, from A it is going to B, from B it is going to C. I am using following code to transfer from one activity to another.
Intent intent = new Intent().setClass(this, B.class);
startActivity(intent);
I want that when I use the back button, it should come to B if it is at C(which is ok for me), but if I use back button at B activity, it should not go to A, it should directly go out the application. How it can be arranged?
Upvotes: 0
Views: 415
Reputation: 10270
In class A you would put:
Intent intent = new Intent(this, B.class);
startActivity(intent);
finish();
This will remove class A from the Activity stack.
Upvotes: 0
Reputation: 6981
There you go
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
this.finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
Upvotes: 3
Reputation: 1133
Override the member function onBackPressed()
inside your Activity
class.
Example:
public void onBackPressed() {
Intent intent = new Intent().setClass(this, B.class);
startActivity(intent);
}
Upvotes: 1