I have 2 Activities
MainActivity
- with 4 tabs
ContactActivity
I make two intents in TaskStackBuilder so the ContactActivity
will appear first and after it MainActivity
when i click on notification.
TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
stackBuilder.addNextIntent(getIntentToMainActivity(context)); // Added extras for tab 1.
final Intent intent = ContactActivity.createIntent(context, 0, phone, false);
intent.putExtra(EXTRA_MISSED_CALL_NOTIFICATION_CLICKED, true);
stackBuilder.addNextIntent(intent);
notificationBuilder.setContentIntent(stackBuilder.getPendingIntent(1000, FLAG_UPDATE_CURRENT));
Scenario:
Click on notification open the ContactActivity correctly.
Press home button.
Click from homescreen on my launcher that open the MainActivity in tab 2.
What that happening now is that the MainActivity opened with tab 1 with the extras of tab 1 that set from stackBuilder (probably from stackBuilder).
Manifest MainActivity:
<activity
android:name=".MainActivity"
android:clearTaskOnLaunch="true"
android:finishOnTaskLaunch="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/contactlist_app_name"
android:launchMode="singleTask"
android:screenOrientation="user">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I added to the subActivity flag:
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
Then its work for me.