title: How to access service in activity from fragment as soon as it's ready?
body: <p>I have a <code>FragmentActivity</code>, and I'm binding to a service in its <code>onResume</code> method. I also have a <code>Fragment</code> that gets added to the activity. The <code>Fragment</code> will call the service from the <code>doInBackground</code> method in an <code>AsyncTask</code> to do some initialization first, and then after the initialization, a button in the fragment will become enabled. But when I tried to execute the <code>AsyncTask</code> from the fragment's <code>onActivityCreated</code> or <code>onResume</code> method, I get a <code>NullPointerException</code> when trying to get the service.</p>
  
  <pre><code>@Override
  public void onResume() {
    new AsyncTask&lt;Void, Void, Boolean&gt;() {
  
      @Override
      protected Boolean doInBackground(Void params) {
        return activity.getMyService().doSomeInit(); // getMyService() returns null
      }
  
      @Override
      protected void onPostExecute(Boolean result) {
        someButton.enabled(result);
      }
  
    }.execute();
  }
  </code></pre>
  
  <p>The activity will connect to the service, but how can I tell the fragment that the service is ready to be used (and therefore no longer null)?</p>