Reputation: 81
Excuse my ignorance but I'm a little distressed...
I would like to have some way of getting the name of the current fragment that is being displayed on the user's screen from a broadCastReceiver or else from a Service class.
currently my broadCast is activated from an alarmManager, where when it is activated it turns on a service to run a feature X... but now I would like him to identify which is the current screen that is being displayed to the user, from this then I can perform another particular function.
I currently have a function that works perfectly on activity and fragments that would be something like this:
val currentDisplay = navController.currentDestination?.displayName.toString()
if there is something like what I can do on broadCasts or Service it would help me a lot...
Upvotes: 0
Views: 384
Reputation: 66
Send local broadcast from service and listen broadcast in your Activity and set some static variable as per open/selected fragment name, then from service read the value of static variable to know the set fragment name.
Or send broadcast from activity back and listen in service.
Upvotes: 1