3

In order to capture incoming SMS in Android, I know that I can either use a ContentObserver that looks at content:/sms/, or I can register a BroadcastReceiver.

What are the pros and cons of these two methods? Is one more reliable than the other? Is one more efficient? Are there any other benefits or drawbacks to one or the other?

I'm writing an app which needs to run under ICS or later, if that makes any difference.

By the way, I have indeed read this discussion: ContentObserver vs. BroadCastReceiver : Battery Usage, Ram, CPU?

I just want to know if there are issues besides battery usage, RAM, and CPU which would favor the use of either a ContentObserver or a BroadcastReceiver for monitoring incoming SMS.

Community
  • 1
  • 1
NYCHippo
  • 377
  • 1
  • 4
  • 14
  • `ContentObserver` and `BroadcastReceiver` are designed to ease your work. So I think there is no problem at all. You can check the documentation of [Content Providers](http://developer.android.com/guide/topics/providers/content-providers.html) (which are related to `ContentObserver`), [`BroadcastReceiver`](http://developer.android.com/reference/android/content/BroadcastReceiver.html). I'm using several content providers and broadcast receivers *within a session*. But I think [my app](https://play.google.com/store/apps/details?id=com.haibison.android.apps.files) works fine :-) –  Mar 10 '13 at 21:10
  • Thank you, Lai Vung. So can I interpret you comment to mean that both BroadcastReceiver and ContentObserver work equally well for monitoring incoming SMS, and that it doesn't matter which one I should choose? – NYCHippo Mar 10 '13 at 21:19
  • Yes I think so. I didn't check the question you mentioned of but just have read it. Its answer is great. I think you don't need to worry about performance. Another note is with broadcast receivers you can break the newly incoming message by calling [`abortBroadcast()`](http://developer.android.com/reference/android/content/BroadcastReceiver.html#abortBroadcast()); but with content observers, you get the message after it has been inserted into database. –  Mar 10 '13 at 22:04

0 Answers0