Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen exactly onServiceConnected for bounded service will be called?
    primarykey
    data
    text
    <p>I am trying to bind service from another service like this:</p> <pre><code>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; } } } </code></pre> <p>This is a simple snippet that I took from goolge's samples :) The code works just fine and mDataService holds a reference to ServiceB instance, but there is one thing I could not understand: the <code>onServiceConnected</code> callback is called after the call to <code>onStart</code>. As I saw on android's docs, <a href="http://developer.android.com/reference/android/content/ServiceConnection.html#onServiceConnected%28android.content.ComponentName,%20android.os.IBinder%29" rel="noreferrer">the callback is running on the main thread</a> - but can I count on it that it will ALWAYS happen in this order in my case? onCreate -> onStart -> onServiceConnected ?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload