title: A convenient way to bind to a local Service in Android
body: <p>In my Android app, I have a service using the <a href="http://developer.android.com/guide/components/bound-services.html#Binder" rel="nofollow">local binder pattern</a> and a couple of activities using the service.</p>
  
  <p>The activities call <a href="http://developer.android.com/reference/android/content/Context.html#bindService%28android.content.Intent,%20android.content.ServiceConnection,%20int%29" rel="nofollow">bindService()</a> in <a href="http://developer.android.com/reference/android/app/Activity.html#onCreate%28android.os.Bundle%29" rel="nofollow">onCreate()</a>, unbindService() in <a href="http://developer.android.com/reference/android/app/Activity.html#onDestroy%28%29" rel="nofollow">onDestroy()</a>  and implement <a href="http://developer.android.com/reference/android/content/ServiceConnection.html" rel="nofollow">ServiceConnection</a> to receive <a href="http://developer.android.com/reference/android/content/ServiceConnection.html#onServiceConnected%28android.content.ComponentName,%20android.os.IBinder%29" rel="nofollow">onServiceConnected()</a> callback when the service connection is available.</p>
  
  <p>If I implement other callbacks of <a href="http://developer.android.com/reference/android/app/Activity.html" rel="nofollow">Activity</a>, such as <a href="http://developer.android.com/reference/android/app/Activity.html#onStart%28%29" rel="nofollow">onStart()</a> and <a href="http://developer.android.com/reference/android/app/Activity.html#onResume%28%29" rel="nofollow">onResume()</a>, is there a well defined order between theses and onServiceConnected(), or can onServiceConnected() be invoked at any time?</p>
  
  <p>I find this pattern quite inconvenient since I won't have the service connection available when onCreate() finish, so I need to litter other methods of the activity with null checks. Is there a more convenient way to do this? I would like a synchronous way to bind to a local service, so that I directly get the connection to it.</p>