Issue
My App has the following activity hierarchy:
A -> B -> C
So far, everything works well. Now I want to add a Notification. When the user clicks on it, I want to close all child activities of A and start an instance of C, which has A as parent, without B as intermediate Activity:
A -> C
To achieve this I used Androids TaskStackBuilder as shown here to build the notification. But this results in the app being closed (without error, checked logcat) when the user presses the back button or uses the up-navigation in the top bar. What did I do wrong?
...
Intent intent = new Intent(NotificationService.this, C.class);
Intent parentIntent = new Intent(NotificationService.this, A.class);
TaskStackBuilder stackBuilder = TaskStackBuilder.create(NotificationService.this);
stackBuilder.addNextIntent(parentIntent);
stackBuilder.addNextIntent(intent);
PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.setContentIntent(pendingIntent);
...
My AndroidManifest.xml looks like this:
<activity android:name=".activities.A"
android:label="@string/app_name"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".activities.B"
android:parentActivityName=".activities.A"
android:launchMode="singleTop">
</activity>
<activity android:name=".activities.C"
android:parentActivityName=".activities.B">
</activity>
Solution
Okay, I was using OxygenOS with an OnePlus One when I discovered this issue. Yesterday, there were some updates and now it works without changing anything.
It works with Intent and with ParentStack as Adeel Ahmad suggested. Maybe it was just an OS issue. Anyways, problem solved. Thanks for your time.
Answered By - Jonas
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.