• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Design advice - services & broadcast receivers

basudz

Lurker
Hey everyone, I'm a mid level software dev and have been learning the sdk and creating some projects to get a grasp on the system.
I am working on a current project which I have gotten to work, but I'm wondering what other ways I can go about designing it.

Here's what it needs to do.
When a text message is received from a specific number, I want to fire off a message that repeats at a certain interval for a specific duration.

1. To make this work, I had set my sms broadcast receiver and checked the incoming messages for the number I'm looking for.

2. When found I would start an intent service that would pull out the interval and duration from saved shared prefs, and then fire off a broadcast.
3. The broadcast receiver for this would catch it and use the alarm manager to handle the toast message repetitions.

This all works just fine, I'm wondering if there's a more elegant way of going about doing this or if there's a way that would be better for the system? Any suggestions or advice?

Thanks!
 
This is actually a fairly clean method of doing things... The only other option I would consider is a Service that periodically checks for new messages, but this isn't nearly as efficient or "pretty" as the method you chose. Good job. =)
 
This is actually a fairly clean method of doing things... The only other option I would consider is a Service that periodically checks for new messages, but this isn't nearly as efficient or "pretty" as the method you chose. Good job. =)

Thanks for the confirmation!

I've actually decided to remove the intent service from the mix. Upon initial sms reception, in the onReceive of that broadcast receiver, it builds up the pending intent and kicks of the alarm manager right from there.

When the alarm manager fires, the second broadcast receiver picks it up and completes the work I need.
I went this route to remove any possibility of the phone falling back asleep after it leaves the onReceive method, (while the intent service is doing its work)...Mind you what I'm doing right now is trivial and shouldn't last long enough for the phone to fall back asleep but I want to learn proper habits!
 
Sounds like you are on the right track. Keep up the good work. =) Intents are generally the hardest concept for developers new to Android to grasp and you seem to be picking them up pretty quickly.
 
Back
Top Bottom