Search code examples
androidandroid-activityservice

Android - how to pass data from service to activity


I have a scenario in which the background service needs to pass data to activity after some interval. How to achieve it and what are the possible ways?


Solution

  • There are different approaches to achieve what you need. The easiest is to use BroadcastReceiver. Register receiver from your activity and send broadcasts from service whenever you need. There are a lot of tutorials on Google on how to use BroadcastReceivers.