I am trying to associate a service with another service, for example:
public class ServiceA extends Service { private ServiceB mDataService; private boolean mIsBound; @Override public void onCreate(){ super.onCreate(); doBindService(); } @Override public void onStart(final Intent intent, final int startId){ } private ServiceConnection mConnection = new ServiceConnection() { public void onServiceConnected(ComponentName className, IBinder service) { mDataService = ((ServiceB.LocalBinder)service).getService(); } public void onServiceDisconnected(ComponentName className) { mDataService = null; } }; void doBindService() { bindService(new Intent(ServiceA.this, ServiceB.class), mConnection, Context.BIND_AUTO_CREATE); mIsBound = true; } void doUnbindService() { if (mIsBound) { unbindService(mConnection); mIsBound = false; } } }
This is a simple snippet I took from goolge selections :) The code works very well and the mDataService contains a reference to the ServiceB instance, but there is one thing that I could not understand: the onServiceConnected is called after the onStart call. As I saw in the android docs, the callback works in the main thread - but can I expect it to ALWAYS happen in this order in my case? onCreate → onStart → onServiceConnected?
ET.
source share