Reputation: 21
i have call Activity A
with state 2 from Activity A
with state 1 then again call Activity A
with state 3 from Activity A
with state 2. Now how can i go back to Activity A
with state 2 when i press on back button in android?
Upvotes: 1
Views: 11287
Reputation:
@Override
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent(CurrentActivity.this, NextActivity.class);
Intent intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();
}
You must Declare i to Intent, It's work for me ( API 23+ )
Upvotes: 0
Reputation: 4377
You can do this using following code-
@Override
public void onBackPressed() {
super.onBackPressed();
i = new Intent(CurrentActivity.this, NextActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();
}
Upvotes: 3
Reputation: 28823
You can override onBackPressed
for that.
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
ActivityB.this.finish();
}
Upvotes: 1