title: BroadcastReceiver with ResultReceiver and lifetime
body: <p>I have interrogation about the way to use a BroadcastReceiver with a ResultReceiver in it.</p>
  
  <p>I know that if "A BroadcastReceiver hasn't finished executing within 10 seconds.", there is an ANR.</p>
  
  <p>I have an application that respond to an Intent, declared in the Manifest.
  It is a BroadcastReceiver that start a service because it needs to make some networks operations:</p>
  
  <pre><code>public class MyReceiver extends BroadcastReceiver {
  
      private Context context = null;
      private MyResultReceiver myResultReceiver = null;
  
      @Override
      public void onReceive(Context context, Intent intent) {
  
          this.context = context;
          myResultReceiver = new MyResultReceiver(new Handler());
  
          Intent i = new Intent();
          i.setClass(context, MyService.class);
          i.putExtra(Constants.EXTRA_RESULT_RECEIVER, myResultReceiver);
          context.startService(i);
      }
  
      public class MyResultReceiver extends ResultReceiver {
  
          public MyResultReceiver(Handler handler) {
              super(handler);
          }
  
          @Override
          protected void onReceiveResult(int resultCode, Bundle resultData) {
              if (resultCode == 42) {
                  // Something
              } else {
                  // Something else
              }
          }
      }
  }
  </code></pre>
  
  <p>My service looks like this:</p>
  
  <pre><code>public class MyService extends Service {
  
      private Context context = null;
      private ResultReceiver resultReceiver = null;
  
      @Override
      public IBinder onBind(Intent intent) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId) {
          this.context = this;
          resultReceiver = intent.getParcelableExtra(Constants.EXTRA_RESULT_RECEIVER);
          MyTask myTask = new MyTask();
          myTask.execute();
          return super.onStartCommand(intent, flags, startId);
      }
  
      public class MyTask extends AsyncTask&lt;Void, Void, Boolean&gt; {
  
          @Override
          protected Boolean doInBackground(Void... params) {
              // Network operation
              return status;
          }
  
          @Override
          protected void onPostExecute(final Boolean status) {
              Bundle bundle = new Bundle();
              if (status == true) {
                  if (resultReceiver != null) {
                      resultReceiver.send(42, null);
                  }
              } else {
                  if (resultReceiver != null) {
                      resultReceiver.send(-1, null);
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p>My question is, am I sure that the resultReceiver still exist and will do what it have to do if the network operation is longer than 10 seconds ?</p>