views:

46

answers:

2

I'm just getting into Android development, and I have a question about communicating between a receiver class and an activity class. I'm very new to JAVA and Android so I hope I don't sound too stupid. I'm developing an application where I intercept an SMS message and then based on various elements of that SMS I might delete it once it's been saved to the inbox. I have a receiver class that intercepts the txt message, and I am also able to delete messages from my inbox with code in the activity class using a button at the moment. The problem I have is communicating between the receiver class and the activity class where the code to delete a message resides. I tried putting that code directly into the receiver class but as I'm sure most of you already know the BroadcastReceiver class doesn't seem to support what I need to delete messages. I've been searching for an answer to this for a while, but haven't been able to find anything. Honestly I'm not sure I know enough about JAVA and Android to even recognize a solution if I saw it. Thanks in advance for any help.

A: 

If you need to complete a job without an interface look into creating a Service, if you need user interface just start an Activity

You can use the Context parameter of the onReceive method of the receiver to start a new service/activity

You can use Extras to pass params between context. So you can put as extra the message id or entire message and pass it to your service/activity and deal it there.

Pentium10
A: 

Thanks a lot for the quick response, it's much appreciated. I took your advice and once I receive the sms I start a service to delete certain messages. The problem is I have the delete function being called from the onCreate method of the service. It seems like this is only allowing the delete function to be run the first time you receive a txt message. Any following text messages won't trigger the delete function I assume because the service has already been created. I tried putting the function call in an onResume function of the service but that didn't work either. Do you have any idea how to address this problem? Thanks again.

Patrick
Nevermind, I moved the function call to the onStart method and then I stop the service once I've done what I want to do and that solved my problem.
Patrick