简体   繁体   中英

How can I use deep link with animation in Android Navigation Component

I'd like to navigate to last page Fragment when restart application.
Ex) MainFragment > UserListFragment > UserDetailFragment
Using the NavDeepLinkBuilder I created deep link because I need create deep link dynamically.

final PendingIntent pendingIntent = new NavDeepLinkBuilder(requireContext())
        .setGraph(R.navigation.nav_graph)
        .setDestination(R.id.userDetailFragment)
        .createPendingIntent();
pendingIntent.send();

It's works as expected but there is no animation.
If I using deeplink by Uri, I might be able to use NavController#navigate(Uri, NavOptions).

Is there a way to use animation with NavDeepLinkBuilder?

Sorry for my bad English.
Thank you.

If you are using navigate you can add another parameter as NavOptions

public void navigate(@NonNull Uri deepLink, @Nullable NavOptions navOptions) {
    navigate(deepLink, navOptions, null);
}

And then create the NavOptions programmatically as

val navOptions =
    NavOptions.Builder()
        .setPopUpTo(
            R.id.nav_graph_main,
            false
        )
        .setEnterAnim(R.anim.slide_in_right)
        .setExitAnim(R.anim.slide_out_left)
        .setPopEnterAnim(R.anim.slide_in_left)
        .setPopExitAnim(R.anim.slide_out_right)
        .build()

Or also you can create the action in the xml as follows

<action
            android:id="@+id/action_notes_to_noteDetail"
            app:destination="@id/noteDetailFragment"
            app:enterAnim="@anim/enter_slide_down"
            app:exitAnim="@anim/exit_slide_down"
            app:popEnterAnim="@anim/pop_enter_slide_up"
            app:popExitAnim="@anim/pop_exit_slide_up" />

For more information, you can check this navigation-architecture-component

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM