简体   繁体   中英

Difference between a BroadcastReceiver and a PhoneStateListener to listen to calls

I know, this may seem alike a "trivial" question, but there is a bit of confusion since there are multiple options available.

I want to listen to phone calls and have found two solutions for doing the same:

These seem to be mutually exclusive. What solution should I prefer? Do they really cater to different use cases? If so, what might they be?

If you use a BroadcastReceiver your application does not need to be running. Android broadcasts call-related events and your BroadcastReceiver will be notified of call-related events and you can do whatever you want to do.

If you use a PhoneStateListener , your application must be running. You will need an Activity or a Service that creates the PhoneStateListener and registers it. Your PhoneStateListener will then be notified of call-related events. When your app is finished or killed by Android you will no longer receive any call-related events.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM