I have a pretty simple local service that I'm trying to bind to my activity. I worked through this yesterday with CommonsWare and he got me straightened out as I was having a difficult time getting the service to bind. It turns out that the reason I was having so much trouble was that I was trying to bind the service with:
bindService(new Intent(this, myService.class), mConnection, Context.BIND_AUTO_CREATE);
inside a void method that was being called after a button click.
private void doBindService() {
bindService(new Intent(this, SimpleService.class), mConnection, Context.BIND_AUTO_CREATE);
mIsBound = true;
}
private OnClickListener startListener = new OnClickListener() {
public void onClick(View v){
doBindService();
}
};
when I moved my bindService() call to the onCreate method of the activity, it works fine. CommonsWare mentioned something about that call being asynchronous and I don't know enough about android activity creation to know if that's what my issue was or not. I do know that my onServiceConnection() was being called inside my ServiceConnection() when the button was being clicked, by my mBoundService would not work when I tried accessing members inside the service.
Can someone tell me why it doesn't work inside the button click, but does work inside the onCreate()?
TIA