Supposing I have the following activities:

  • Activity A
  • Activity B
  • Activity C
  • Activity D

A calls B, B calls C and C calls D, so my stack is, from top to bottom, D-C-B-A.

Now I want call from D the activity B in order to obtain the following stack:

B-A

Where B is not the previous instance that was in the initial stack configuration (D-C-B-A) but is a new instance.

What FLAG_ACTIVITY_ I have to use?

I have tried using this :

intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP);

But this give me the old instance of Activity B, on top of the stack.

有帮助吗?

解决方案

Take out the flag Intent.FLAG_ACTIVITY_SINGLE_TOP. From the docs:

The currently running instance of activity B in the above example will either receive the new intent you are starting here in its onNewIntent() method, or be itself finished and restarted with the new intent. If it has declared its launch mode to be "multiple" (the default) and you have not set FLAG_ACTIVITY_SINGLE_TOP in the same intent, then it will be finished and re-created; for all other launch modes or if FLAG_ACTIVITY_SINGLE_TOP is set then this Intent will be delivered to the current instance's onNewIntent().

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top