WAI
Status Update
Comments
lo...@gmail.com <lo...@gmail.com> #2
After some further testing it seems that this behaviour was caused by the line android:launchMode="singleTask" set for the main activity in the manifest file.
il...@google.com <il...@google.com>
il...@google.com <il...@google.com> #3
This is working as intended. When you use launchMode="singleTask", all intents are sent to your task, whether the calling app uses the NEW_TASK flag or not. To ensure a valid back stack on your task, Navigation ensures that every NEW_TASK intent also has the CLEAR_TASK flag.
If your task is started without the CLEAR_TASK flag, NavController will automatically recreate the task stack and finish your current instance.
I'd strongly suggest not using singleTask at all as it prevents your app from appearing on other app's task stack, breaking user expectations on what back stack they are manipulating / what appears in Recents.
If your task is started without the CLEAR_TASK flag, NavController will automatically recreate the task stack and finish your current instance.
I'd strongly suggest not using singleTask at all as it prevents your app from appearing on other app's task stack, breaking user expectations on what back stack they are manipulating / what appears in Recents.
lo...@gmail.com <lo...@gmail.com> #4
I already removed the singleTask attribute. Nevertheless thanks for your detailed explanation!
Description
What I expect: call onNewIntent() only once containing the URL, so that it can be handled by the navigation component to show my fragment.
What I get: onNewIntent() is called twice, so that my fragment is created twice and the sync operation starts a second time.
I setup two deep links the following way (identifiers changed):
<fragment
android:id="@+id/someFragment"
android:name="com.example.courses.someFragment"
android:label="someFragment"
tools:layout="@layout/some_fragment">
<deepLink app:uri="myURL/courses/{courses}"/>
<deepLink app:uri="myOldURL/upload-courses/{courses}"/>
<argument
android:name="courses"
app:nullable="true"
android:defaultValue="@null"
app:argType="string" />
</fragment>
The layout of my main activity contains:
<fragment
android:id="@+id/modulesNavHostFragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="@navigation/navigation_graph" />
In my main activity I'm overriding the onNewIntent() method to also catch deep links when the app is already running in the background (as stated out here
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
if(findNavController(R.id.modulesNavHostFragment).onHandleDeepLink(intent)){
return
}
setIntent(intent)
}
I am using the following versions of the navigation component:
def nav_version = "1.0.0-alpha05"
implementation "android.arch.navigation:navigation-fragment-ktx:$nav_version"
implementation "android.arch.navigation:navigation-ui-ktx:$nav_version"
classpath "android.arch.navigation:navigation-safe-args-gradle-plugin:1.0.0-alpha05"