Clear all actions except one in android

Below I show how I want to navigate through Activities:

enter image description here

I tried to write the following code inside Dand E:

Intent list = new Intent(AddComplaint.this, B.class);
list.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(list);

However, I ran into two problems:

  • When it starts B, a gray screen is displayed for a while, then it loads.
  • When I get back from B, it exits the application, and does not go to A(dashbord).

How can i fix this?

+4
source share
2 answers

, , , FLAG_ACTIVITY_CLEAR_TOP. Intent , B, B (C, D/E) .

FLAG_ACTIVITY_CLEAR_TASK , B - , . , , onCreate().

:

Intent list = new Intent(AddComplaint.this, B.class);
        list.setFlags
                (Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(list);
+3

, FLAG_ACTIVITY_CLEAR_TASK .

B A, , onBackPress() B startActivity A .

0

All Articles