aspose file tools*
The moose likes Android and the fly likes Beginning Android, activity / service question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Android
Bookmark "Beginning Android, activity / service question" Watch "Beginning Android, activity / service question" New topic
Author

Beginning Android, activity / service question

Espen Myklevoll
Greenhorn

Joined: Apr 26, 2011
Posts: 2
So, I just started playing around with the Android SDK, and I'm slightly confused about a couple of things.

The app I'm creating is supposed to send an SMS message on user request, and intercept / parse incoming messages. If the incoming message is from a number defined by the application, and the message content corresponds to one of many locally stored text formats, the message will be processed by the application and kept out of the inbox.

Example:
User triggers an action that sends message "balance" to a number, the following message is returned: "Balance: 130$". The message is parsed and used in the application.

Lets see some code, then. The following code is executed in the current action:


SmsSender class:


This part works just fine. The service is started, message is sent, result is logged, service is destroyed. What i'm wondering is, is it correct to use a service at all in this case? Not an activity? I figured that since that since there's no view associated with this action, a service was appropriate.
If a service is the way to go, am I ending the service the right way? Ref unregisterReceiver() and stopSelf().


All the above code works as intended. The part I'm struggling with is when the external service returns a message. I have created a class extending BroadcastReceiver that monitors for incoming messages.



Now, the test in line 17 is obviously temporary. It works though, no notification is triggered, and the message is not placed in the inbox. What I need here is something parsing the message body and checks if it corresponds to one of many formats stored in an SQLite DB. Any tips on how to implement this? I'd prefer to have this validation in a separate activity/service, as I will probably use it in more that just this part of the code.

Again, I'm just starting to learn the Android API, so constructive feedback is more than welcome

Oh, and sorry for the wall of text.
 
Consider Paul's rocket mass heater.
 
subject: Beginning Android, activity / service question