-1

[Revising my question per @CommonWare's feedback]

I am trying to insert a record into a SQLite database for each SMS message the app receives from an external GPS transmitter (i.e., not from the phone's GPS). All SMS's are processed by my BroadcastReceiver ("SMSReceiver") which is registered in the Manifest with a priority of 999. The BroadcastReceiver aborts the broadcast if the SMS was sent by the GPS device and passes it on if not.

What is the best way of ensuring that that ALL SMS's are processed by my app while dealing with the possibility that the device may fall asleep or my process may be terminated?"

The BroadcastReceiver docs mention "for longer-running operations you will often use a Service in conjunction with a BroadcastReceiver to keep the containing process active for the entire time of your operation." This sounds like what I need but they provide no instructions on how to do that. Any guidance, especially with code examples, would be appreciated. And, in my case, the 'operation' needs to be active for as long as the phone is powered on.

PeteH
  • 1,870
  • 25
  • 23
  • Easiest method is probably a foreground service. – A--C Jan 09 '13 at 23:35
  • What makes you think that the code above has anything to do with "receiving a stream of SMS messages"? – CommonsWare Jan 09 '13 at 23:37
  • to receive SMS you would use a BroadcastReceiver, but your code have nothing to do with SMSs – Budius Jan 09 '13 at 23:56
  • Guys, the SMS Receiver is built and fully functional. That is not my problem. Please revisit your downgrades on the question. As I stated clearly I am looking for a way to keep the app (which includes the 100% working SMS receiver) from being paused/destroyed. – PeteH Jan 10 '13 at 01:11
  • @A--C: thanks for your suggestion. I did a search and found this article: http://stackoverflow.com/questions/5383300/android-foreground-service-which-can-be-bound. Do you recommend any info sources on how to implement the foreground service? – PeteH Jan 10 '13 at 01:16
  • @PeteH: What makes you think that SO question has anything to do with "receiving a stream of SMS messages"? – CommonsWare Jan 10 '13 at 01:18
  • @PeteH: "the SMS Receiver is built and fully functional" -- then post it, or at least describe in decent detail what it is and how you have it working. Eventually, you will hopefully realize that you are asking the wrong questions, and you should be asking "I am trying to do X with a received SMS message that I obtained via Y -- what is the best way of going about that while dealing with the possibility that the device may fall asleep or my process might be terminated?". – CommonsWare Jan 10 '13 at 01:23
  • @CommonsWare: Since my last comment I've been researching Services and BroadcastReceivers and concluded exactly what you just stated: I asked the wrong question. Let me start afresh. – PeteH Jan 10 '13 at 07:49
  • Here's the revised question: I am trying to insert a record into a SQLite database for each SMS messages the app receives from an _external_ GPS transmitter (i.e., not from the phone's GPS). All SMS's are processed by the BroadcastReceiver ("SMSReceiver") which is registered in the Manifest with a priority of 999. The BroadcastReceiver aborts the broadcast if the SMS was sent by the GPS device and passes it on if not. What is the best way of ensuring that that ALL SMS's are processed by my app while dealing with the possibility that the device may fall asleep or my process may be terminated?" – PeteH Jan 10 '13 at 08:05

1 Answers1

1

You need to write a class that extends BroadcastReceiver and add it to your AndroidManifest.xml file to receive an appropriate SMS action.

Anton Cherkashyn
  • 5,719
  • 6
  • 43
  • 80
  • Let me reiterate: the SMS Receiver is already built and 100% functional. As I stated in the original question: I am looking for a way to keep the app (which includes the 100% working SMS receiver) from being paused/destroyed. I'm looking into the foreground service suggestion now. Any other constructive suggestions would be appreciated. – PeteH Jan 10 '13 at 01:22