-1

I have a Service [a] that is logging sensor data. This service is bound to the calling service [b]. However, i need to start the logger-service manually with startService(intent) bevor binding because i need th onCreate()-Method to run.

Is there a way to kill the Service [a] so that [b] is informed? (preferable from within the onSensorChanged-method of [a] and in a way that onServiceDisconnected is being called)

Jan
  • 343
  • 2
  • 16

1 Answers1

0

According to the accepted answer of this Question, it is actually very simple. After calling startService() just bind to the Service and put the Context.BIND_NOT_FOREGROUND-flag.

If you then call stopSelf() (after unregister the listener in my case) from within the bound service, the process is destroied and onServiceDisconnected will be called. It might be not the best solution because onServiceDisconnected will also be called if some error kills the service... Better would be sending a broadcast. But it solved my problem.

Community
  • 1
  • 1
Jan
  • 343
  • 2
  • 16