Ask Your Question
3

When using setLaunchSingleTop(true) in Navigationcomponent, how can we avoid losing the bundle arguments during navigation?

asked 2023-06-24 07:38:25 +0000

nofretete gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-24 08:05:01 +0000

plato gravatar image

To avoid losing the bundle arguments during navigation while using setLaunchSingleTop(true), we can use the following approach:

  1. Create a new navigation action with the destination that has setLaunchSingleTop(true) set to true.

  2. Add the arguments to this new action instead of the original action.

  3. Override the onNewIntent(Intent) method in the activity that hosts the navigation component.

  4. Inside onNewIntent(Intent), get the arguments from the intent using getArguments() method and pass them to the navigate() method of the navigation controller.

  5. Finally, call the super.onNewIntent(Intent) method to ensure that the default behavior is not affected.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-24 07:38:25 +0000

Seen: 8 times

Last updated: Jun 24 '23