Thread used for ServiceConnection callback (Android)

Posted by Jannick on Stack Overflow See other posts from Stack Overflow or by Jannick
Published on 2010-05-10T22:58:56Z Indexed on 2010/05/10 23:04 UTC
Read the original article Hit count: 256

Hi

I'm developing an activity that binds to a local service (in onCreate of the activity):

bindService(new Intent(this, CommandService.class), svcConn, BIND_AUTO_CREATE);  

I would like to be able to call methods through the IBinder in my lifecycle methods, but can not be sure that onServiceConnected have been called prior to these. I'm thinking of handling this by adding a queue of sorts in the ServiceConnection implementation, so that the method calls (Command pattern) will be executed once the connection is established.

My questions are then:

  1. Is this stupid, any better ways? :)
  2. Are there any specification for which thread will be used to execute the ServiceConnection callbacks? More to the point, do I need to worry about synchronizing a queue datastructure?

Edit - something like:

public void onServiceConnected(ComponentName name, IBinder service) {
    dispatchService = (DispatchAsync)service;

    for(ExecutionTask task : queue){
        dispatchService.execute(task.getCommand(), task);
    }
}

© Stack Overflow or respective owner

Related posts about android

Related posts about service