My app receives pushes and opens different activities according to the push type.
I use TaskStackBuilder
for a pending Intent to create a synthetic backstack in conjunction with android:parentActivityName
in my manifest.
So far, so easy. When the App is not started, all works as expected. But if the app is in background (task is running), the pending Intent also starts my desired activity with the defined parent from the manifest, but resets the existing task. The problem is that other activities that were started by the user in the meantime are also cleared.
So what a want to achieve is:
I can't seem to make it work with the TaskStackBuilder
.
I'd be happy for some insights.
You can't really do this with TaskStackBuilder
. It isn't designed for that. It always resets the task to begin with.
I would do the following:
Activity
. Don't use TaskStackBuilder
and don't create any artificial back-stack. This Activity
will run in the application's current task if the application is currently active, and it will be put on top of the most recent Activity
that is open.onCreate()
of this new Activity
, check if this Activity
is the root of the task using isTaskRoot()
. If this Activity
is the root of the task, this means that the app was not active prior to launching this Activity
. In this case, you can create an artificial back-stack using TaskStackBuilder
and launch the thing again the way you want it (this will reset the task).