Answers

Question and Answer:

  Home  Android Developer

⟩ Tell us how would you update the UI of an activity from a background service?

We need to register a LocalBroadcastReceiver in the activity. And send a broadcast with the data using intents from the background service. As long as the activity is in the foreground, the UI will be updated from the background. Ensure to unregister the broadcast receiver in the onStop() method of the activity to avoid memory leaks. We can also register a Handler and pass data using Handlers.

 150 views

More Questions for you: