سؤال

To lay it out as simply as possible. My user enters the app through Activity A. They "login" and then Activity B is started, and Activity A is finished using finish() so that the users can't get back to the login screen by pressing back from Activity B. Now in Activity B, they move to Activity C, and in activity C, I want them to start a new intent that will start activity A, but "kill"/"finish" all other activities. The only way I can think of doing this is using an Intent Flag. so far I've come up with:

Intent intent = new Intent(getActivity(), ActivityA.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
startActivity(intent);

But the code above doesn't work. I still see that my app had a savedInstanceState in Activity B. Hence something like CLEAR_TASK won't work for me case.

EDIT: Also, is there an easy way to tell have many "tasks" your app has opened currently?

Note: There seems to be other flags that may help, but they were added in API 11, and I need to support API 10.

Flag combos I've tried:

Doesn't work

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET|Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

Doesn't work

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
هل كانت مفيدة؟

المحلول

You need to use IntentCompat. like

import android.support.v4.content.IntentCompat;
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |IntentCompat.FLAG_ACTIVITY_CLEAR_TASK);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top