Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to navigate from Service to a Navigation Fragment using probably Pending Intent?

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.

like image 786
Riajul Avatar asked Apr 29 '19 18:04

Riajul


People also ask

How do you go from activity to fragment?

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.

How do I go back to previous fragment in navigation component?

Use Up or Back button to go to a previous step of the order flow.


1 Answers

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)
like image 115
Beyazid Avatar answered Oct 27 '22 00:10

Beyazid