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. How to force a GSM call to be handled by the native dialer?

I am writing a an application that makes a GSM call. I would like this
call to be handled by the native dialer but I have found that if there
any applications installed that can handle GSM calls (Google Voice for
instance) then the call can be intercepted before reaching the native
dialer.

Is there a way I can force the intent to always resolve to the native
dialer? I have used PackageManager.queryBroadcastReceivers() to try
and identify information that could be used to target the intent to
the native dialer but to no avail. Using Intent.setComponent() is
presumably only safe for components inside your own application as
others may change.

T.I.A,
Jack

--~--~---------~--~----~------------~-------~--~----~

2. 绛斿: detect usb device

if only detect usb pluged in or not when sometime, you may be use:
mBatteryService.getPlugType().



                                                                           
             tstanly                                                       
             <tsai.sta...@gmai                                             
             l.com>                                                 
                                Android Developers                  
             android-developer         <android-develop...@googlegroups.co 
             s...@googlegroups.co         m>                                  
             m                                                        €
                                                                           
                                                                       
             2009-09-07 13:57          [android-developers] Re: detect usb 
                                       device                              
                                                                           
                                                                 
             android-developer                                             
             s...@googlegroups.co                                             
                     m                                                     
                                                                           
                                                                           





thanks!

and the other question,
is Android detect dynamically possible(on listening mode)?

that is,
when I'm in the Activity1, and insert a usb device,
then app can detect right now and use dialog send a message to user
the device is mounted!?

thanks

On 9 10 "Roman ( T-Mobile USA)" <roman.baumgaert...@t-







--~--~---------~--~----~------------~-------~--~----~

3. Multi-touch

4. Where are the Android Sources, like strings display on the device,where are they?

5. detect usb device

6. How do I search an xml feed?

7. How to know software keyboard is on screen or not?