> Hello
>
> I made two applications. One for an activity receiving user input, the
> other for a background service.
> In the service package, I create two files
> (startSensorBroadReceiver.java, remoteService.java).
> StartSensorBroadReceiver will receiver an intent from activity
> application and call method inside of the service.

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

> There is no erron in the codes but I can not excute what is want.
> I meet a message like this "The application ServiceExample has stopped
> unexpectedly. Please try again."
>
> could you let me know. what is wrong? and how I can call service
> methods from broadcastReceiver?

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


-- 
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

Reply via email to