I am trying to implement deep linking in my Android application. I have been following this guide. I have an Android Activity that is started from and intent-filter in the Android manifest:
<activity
android:name=".MyActivity"
android:parentActivityName=".MainActivity" >
<intent-filter android:label="@string/filter_title_deep_link">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="com.example" />
</intent-filter>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity"/>
</activity>
I am spawning this intent from adb:
adb shell am start -W -a android.intent.action.VIEW -d "com.example://test" com.example
The activity is being created with the correct intent data and runs as expected. However, on press of the back button, the application exits. I was expecting the back stack to be built with MainActivity
, as specified by parentActivityName
in the Android manifest. Obviously this is not the case.
How can I add a parent activity to the back stack in this case?
I wondered if I could use a TaskStackBuilder
as shown here in the context of notifications, but wasn't sure how it would work.
Perhaps I should have an intermediate Activity to build the main activity using something like:
TaskStackBuilder.create(this)
.addParentStack(MyActivity.class)
.addNextIntent(new Intent(this, MyActivity.class))
.startActivities();
?