I tested with blocking some lines of function call inside of
startSensor() and stopSensor().
Then there is no failure message.

Does any expert know how to call those function in startSensor(),
stopSensor().
Please tell me how~

/**
* remoteService.java
*/
public class RemoteService extends Service {

  //emit codes...

  SensorManager sensorManager;


  public void startSensor(){
    //String service_name = Context.SENSOR_SERVICE; <---block
    //sensorManager = (SensorManager)getSystemService(service_name);
<---block
    //sensorManager.registerListener(accelSensorListener, <---block
    //
SensorManager.SENSOR_ACCELEROMETER,SensorManager.SENSOR_DELAY_UI); <---
block
  }


  public void stopSensor(){
    //sensorManager.unregisterListener(accelSensorListener); <---block
  }

     //emit codes...
}


On 12월7일, 오후5시18분, MSChoi <[email protected]> wrote:
> I am very apperciate with your answer.
>
> 1. Maybe you can not raise a Toast from aBroadcastReceiverbecasue
> the string resource is not matching with my code.
>     You can test the code after erase all "Toast" inBroadcastReceiver.
>
> 2. As you mentioned before , I created an activity in other
> application which calls statService method, so I could start service.
>
> 3. I understand your idea. I can add more information in an intent and
> I can do what I want at the start of the sevice or end of it.
>    But I still need to handle the service during service life cycle,
> using an activity in the other application.
>    Could you give me more information or sample code about it.
>
> Thank you.
>
> On 12월7일, 오후4시39분, "Mark Murphy" <[email protected]> wrote:
>
>
>
> > > 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 frombroadcastReceiver?
>
> > 1. I would not raise a Toast from aBroadcastReceiver.
>
> > 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 aBroadcastReceiververy
> > 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 aBroadcastReceiverusing startService() to
> > start up a service here:
>
> >http://github.com/commonsguy/cw-advandroid/tree/master/SystemServices...
>
> > --
> > 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