I'm trying to open a fragment with args from my notification. Actually, in my case, I have Audio Player running with Foreground Service with Notification and now I want to navigate to my fragment for that specific Audio by passing Audio Id when a user clicks to the Notification.
Can I go from fragment to activity Android? You can add your fragment to the activity's view hierarchy either by defining the fragment in your activity's layout file or by defining a fragment container in your activity's layout file and then programmatically adding the fragment from within your activity.
Use Up or Back button to go to a previous step of the order flow.
You can open your activity with PendingIntent
then open your fragment via handling the Intent
inside of your activity.
or this answer from similar topic
NavDeepLinkBuilder:
val pendingIntent = NavDeepLinkBuilder(context)
.setComponentName(YourActivity::class.java)
.setGraph(R.navigation.your_nav_graph)
.setDestination(R.id.your_destination)
.setArguments(bundle)
.createPendingIntent()
//then
notificationBuilder.setContentIntent(pendingIntent)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With