What is the difference between a Listener and a Receiver (Android)?

前端 未结 4 1048
余生分开走
余生分开走 2020-12-25 13:12

For instance, I need a BroadcastReceiver to get these events:

REBOOT or SHUTDOWN

SCREEN ON or OFF

battery status (voltage, plugged in, temperature)

4条回答
  •  爱一瞬间的悲伤
    2020-12-25 13:34

    Both Listeners and Receivers act as trigger handlers, however, it is the origin and characteristics of these triggers that separates them.

    (Broadcast) Receivers are triggered by Intents. The origin of these Intents can come from outside the context of your own application. Thus, it is a way for applications to implement Inter-Process Communication.

    In addition, applications do not need to be running to receive Intents. Intents can act as an alarm clock to wake applications up when an event has been triggered. This saves battery and cpu.

提交回复
热议问题