woshidan's loose leaf

ぼんやり勉強しています

Intentのフラグを使ってスタックの下の方のActivityをクリアする

下記のフラグをつけてstartActivityする。

Intent intent = new Intent(ThirdActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);

サンプルコード https://gist.github.com/woshidan/72bafcbcfabbd4c91a1ee092e36c3a9f

参考

https://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_CLEAR_TASK