How can I call service methods from broadcastReceiver?

by Mark Murphy » Mon, 07 Dec 2009 15:40:12 GMT


Sponsored Links
 > Hello

I would get rid of the broadcast receiver and just have the activity work
with the service.


1. I would not raise a Toast from a BroadcastReceiver.

2. You cannot call new RemoteService() to create an Android service. You
need to call startService() with an appropriate Intent to start up your
RemoteService. And, bear in mind that the service will not be started
until after your onReceive() method returns.

3. You cannot call methods on a service from a BroadcastReceiver very
easily. I would strongly recommend you find some other solution (e.g., put
extras on the Intent you use with startService(), so your service learns
what to do from those extras alone).

You can see an example of a BroadcastReceiver using startService() to
start up a service here:

 http://github.com/commonsguy/cw-advandroid/tree/master/SystemServices/Alarm/ 

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
Android App Developer Books:  http://commonsware.com/books.html 


--



Other Threads

1. Read SMS that are already stored (from the MMS application)

Hi everybody,

I am modifying the MMS application. I want to read all the SMS that
are already received. I cannot find any contentprovider or any ways to
read them. Any suggestions ?

I want to achieve something like :

SmsMessage[] messages = getAllStoredSMS();
for (SmsMessage msg : messages) {
  //SMS analysis
}

:::::
PS: my goal is NOT to read the incoming messages that could be done by
reading this tutorial : http://www.helloandroid.com/node/159?page=0%2C1

Thank you a lot for your help.
Deniz
--~--~---------~--~----~------------~-------~--~----~

2. Setting Single Choice Dialog Checked Item

How do you set the checked item of a single choice dialog, after the
dialog has been created?
Subsequent calls to showDialog() seem to remember and display the
user's last checked item.  I want to set the checked item myself, each
time the dialog is displayed.

Is there some way to set the selected item in onPrepareDialog() or
elsewhere?

Thanks.
--~--~---------~--~----~------------~-------~--~----~

3. Some stacktraces do not show up in logcat output

4. Webview Question: onCreate always get called when activity comes to foreground

5. How to add a .so library to prelink map?

6. Camera HAL Crashes in android running on beagle

7. Some stacktraces do not show up in logcat output