0

I need to decouple a code from my app. The service seems to do pretty much the job I need, except 1 thing. My activity needs 1 worker thread (ListeningThread) that is running in infinite loop (listening, until the service is stopped) AND the app also calls custom methods, that should be executed just once (almost instantly).

So far my (vague) idea is to have a service that starts working thread + the custom methods might be called in a fashion of class instance ---> service.customMethod().

I came across iBinder, is this the (only) solution? Or is there any other way it can be done?

Martin G
  • 268
  • 1
  • 3
  • 20

1 Answers1

0

Why use an infinite loop thread to only listen for service stopping? You can use LocalBroadcastManager or system wide broadcast to do so. IBinder is needed if the communication between activity and service is very frequent. Check this, this, and this.

Community
  • 1
  • 1
muntasir2000
  • 204
  • 1
  • 3
  • 11
  • NO NO NO ... the worker thread is doing something (it is continuously listening to incoming messages produced be by FTDI library methods) until it is forced to stop (because the app is canceled/stopped) – Martin G Oct 27 '13 at 11:14