In Android I have some activities, let\'s say A, B, C.
In A, I use this code to open B:
Intent intent = new Intent(this, B.class);
startActivity(inte
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
Use this code for starting a new Activity and close or destroy all other activity stack or back stack.
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
Add NO History Flag in the intent.
In activity B, start the activity C as below >>>>>>
Intent intent = new Intent(this, C.class);
intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intent);
finish();
Use setFlags() method for clear back side opened all activity close and start yourActvity
Intent intent = new Intent(getApplicationContext(), yourActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
for me adding Intent.FLAG_ACTIVITY_CLEAR_TASK
solved the problem
Intent i = new Intent(SettingsActivity.this, StartPage.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
finish();
Either add this to your Activity B
and Activity C
android:noHistory="true"
or Override
onBackPressed
function to avoid back pressing with a return
.
@Override
public void onBackPressed() {
return;
}