Difference between Service and Broadcast receivers in android

╄→гoц情女王★ 提交于 2019-11-30 12:56:54

问题


I want to know the difference between services and broadcast receivers, can anyone point out an example that can be observed on android mobile devices. Thanks


回答1:


Service: If you want to do something in background , this will be running always in background even if the application closed. You can create this in separate process and also you can give your service to other app if you want. Downloading any content or Music is good example

Broadcast Reciever: Usually system will send some info which can be recieved by your app if you would wish to ,by registering. And you can do something what you want when that thing happens by using onReceive method. Example is the system will send BroadcastReceiver when new sms arrives or Booting done

Here is good article : Service and BroadcastReceiver




回答2:


Service is used when you want to do something in background, any long running process can be done using Service in Background. For example, you want to play music when your application gets close. In that case service will be running in background with music.

Example of Service

BroadcastReceiver is used when you want to fire some stuff or code during some event. For example, event can be on Boot of Device. If you want to perform something when device Boots, date and time changed etc...

Example of BroadcastReceiver



来源:https://stackoverflow.com/questions/8889954/difference-between-service-and-broadcast-receivers-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!