Skip to content Skip to sidebar Skip to footer

Android Start Service Issue In Oncreate Of Activity

I have tried to start a service and bind to the service in my Activity's onCreate() method. When I try to call a function from service like commSessionManagerService.startCommandUp

Solution 1:

This is because your Service is actually bound on the UiThread. As onCreate also runs on UiThread, your call to bindService result in Handler.post(Runnable) be called on the main thread's handler.

So when bindService returns, the Service isn't already bound. To circumvent this problem, you should put your code using your Service inside ServiceConnection.onServiceConnected().

Post a Comment for "Android Start Service Issue In Oncreate Of Activity"