title: How to wait until onActivityResult finishes?
body: <p>I have a fragment that shouldn't be opened if a user does NOT approve activation of Bluetooth, which is requested via this piece of code</p>
  
  <pre><code>    Intent mIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
          mIntent.putExtra(BluetoothAdapter.EXTRA_DISCOVERABLE_DURATION, 240);
              startActivityForResult(mIntent, 1);
      //Here I want to exit the method in case result is denied
  getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.content,new ServerFragment()).addToBackStack(null).commit();
  </code></pre>
  
  <p>I've been looking in quite a few places and the only thing I've found is to use the setResult from a new activity (in my case, the onActivityResult is overridden in the calling activity since this code is within a fragment)</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT:</strong> Here's a stack trace</p>
  
  <pre><code>java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=131073, result=240, data=null} to activity {bt.bt/bt.bt.MainActivity}: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
                                                                                 at android.app.ActivityThread.deliverResults(ActivityThread.java:3659)
                                                                                 at android.app.ActivityThread.handleSendResult(ActivityThread.java:3702)
                                                                                 at android.app.ActivityThread.access$1300(ActivityThread.java:155)
                                                                                 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1366)
                                                                                 at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                 at android.os.Looper.loop(Looper.java:135)
                                                                                 at android.app.ActivityThread.main(ActivityThread.java:5343)
                                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                                 at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:905)
                                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:700)
                                                                              Caused by: java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
  </code></pre>