Thread used for ServiceConnection callback (Android)
- by Jannick
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:
Is this stupid, any better ways? :)
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);
}
}