Home » Android » android – TaskStackBuilder.addParentStack not working when I was building a notification

android – TaskStackBuilder.addParentStack not working when I was building a notification

Posted by: admin May 14, 2020 Leave a comment

Questions:

I did everything as the official docs writes.But when i navigate backwards,the MainActivity(parent) doesn’t open.Instead, the application closes.

here is my code:

Intent resultIntent = new Intent(context, TestActivity.class);

TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addParentStack(TestActivity.class);
stackBuilder.addNextIntent(resultIntent);

the manifest is as below:

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".TestActivity"
        android:parentActivityName=".MainActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".Main2Activity" />
    </activity>

Thank you.

How to&Answers: