I see, but I understand that already. The problem is that the service itself is already started, and a BroadcastReceiver cannot perform bindService or startService. The only way of communicating between a BroadcastReceiver and a Service is using peekService. Or can I perhaps embed a BroadcastReceiver inside my Service in any way?
Cheers, Ola On 16 Juli, 20:44, Dianne Hackborn <[email protected]> wrote: > Actually let me put this another way -- if you want guarantees about your > communication happening with the service, you absolutely do not want > peekService(). You should use startService() and send it a command. Where > peekService() makes sense is for background music playback, where if it > fails it is because playback is not happening and we don't care. > > On Thu, Jul 16, 2009 at 11:43 AM, Dianne Hackborn <[email protected]>wrote: > > > > > > > Calling startService() is not enough -- you need to have called > > bindService() for the same intent, so the system had retrieved the IBinder > > for it. It needs to have been kept running. This is useful for something > > like background media playback, which has a published interface whiloe it is > > running (and is in fact what it was added for), but perhaps little else. :} > > > On Thu, Jul 16, 2009 at 6:29 AM, Ola <[email protected]> wrote: > > >> I'm having a problem using peekService(Context, Intent) from my > >> BroadcastReceiver to notify a Service of an event. > > >> I have written a little application that sends an SMS and verifies > >> that it is sent. It is run as a Service, not an Activity, in order to > >> send text messages from the background. I have a BroadcastReceiver > >> that listens to the "Sms sent successfully" and "Sms delivered > >> successfully" intents that are broadcast when the message is sent and > >> delivered. > > >> The messages are sent successfully and the BroadcastReceiver is then > >> triggered and it prints into the log when the message is sent and when > >> it is delivered. I however want the BroadcastReceiver to tell the > >> Service that the message is sent successfully, so the service knows if > >> it was successful. This is where the peekService method seems to be > >> suitable. I'm calling it from the BroadcastReceiver's onReceive > >> method, but peekService only returns a null IBinder, which obviously > >> is of no use to me. > > >> The Service is still running and has not been destroyed. It is > >> sleeping for 15 seconds at 1-second intervals and printing that into > >> the log, waiting for the BroadcastReceiver to notify it of a sent > >> message. > > >> The Intent I use in peekService is _identical_ to the one I used when > >> calling startService in the first place, so the intent should be > >> correct, since starting the Service worked. > > >> There is sadly no useful log to paste here, all it does is prints that > >> my IBinder is null, a NullPointerException. > > >> Cheers, > >> Ola > > > -- > > Dianne Hackborn > > Android framework engineer > > [email protected] > > > Note: please don't send private questions to me, as I don't have time to > > provide private support, and so won't reply to such e-mails. All such > > questions should be posted on public forums, where I and others can see and > > answer them. > > -- > Dianne Hackborn > Android framework engineer > [email protected] > > Note: please don't send private questions to me, as I don't have time to > provide private support, and so won't reply to such e-mails. All such > questions should be posted on public forums, where I and others can see and > answer them. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

