title: How to fix Exception: Failure deliviring result ResultInfo
body: <p>I have an application that displays a dialog with a listview. After the user chooses an option from the listview, I will change a record using the information that the user selects.
  For this I thought about using the command <code>setResult (RESULT_OK, intent);</code> but my code is generating the following exception:</p>
  
  <pre><code>09-25 12:01:06.035: E/AndroidRuntime(8783): FATAL EXCEPTION: main
  09-25 12:01:06.035: E/AndroidRuntime(8783): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=0, result=-1, data=Intent { flg=0x20000000 cmp=com.sisteplantbrasil/.WorkOrderInfo (has extras) }} to activity {com.sisteplantbrasil/com.sisteplantbrasil.WorkOrderInfo}: android.os.NetworkOnMainThreadException
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3182)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at android.app.ActivityThread.handleSendResult(ActivityThread.java:3225)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at android.app.ActivityThread.access$1100(ActivityThread.java:140)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1275)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at android.os.Handler.dispatchMessage(Handler.java:99)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at android.os.Looper.loop(Looper.java:137)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at android.app.ActivityThread.main(ActivityThread.java:4898)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at java.lang.reflect.Method.invokeNative(Native Method)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at java.lang.reflect.Method.invoke(Method.java:511)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at dalvik.system.NativeStart.main(Native Method)
  09-25 12:01:06.035: E/AndroidRuntime(8783): Caused by: android.os.NetworkOnMainThreadException
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1118)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:84)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at libcore.io.IoBridge.connectErrno(IoBridge.java:144)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at libcore.io.IoBridge.connect(IoBridge.java:112)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:459)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at java.net.Socket.connect(Socket.java:842)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at libcore.net.http.HttpConnection.&lt;init&gt;(HttpConnection.java:76)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at libcore.net.http.HttpConnection.&lt;init&gt;(HttpConnection.java:50)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:315)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at libcore.net.http.HttpEngine.connect(HttpEngine.java:310)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:289)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:239)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:76)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:146)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at com.sisteplantbrasil.webservices.PrismaWebServices.getDateTimeNow(PrismaWebServices.java:144)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at com.sisteplantbrasil.entities.LaborRecord.getCurrentDate(LaborRecord.java:120)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at com.sisteplantbrasil.entities.LaborRecord.getLaborEndDate(LaborRecord.java:146)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at com.sisteplantbrasil.queries.sql.LaborRecordDBQueries.insertLaborRecord(LaborRecordDBQueries.java:35)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at com.sisteplantbrasil.entities.LaborRecord.offlineSave(LaborRecord.java:167)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at com.sisteplantbrasil.WorkOrderInfo.onActivityResult(WorkOrderInfo.java:492)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at android.app.Activity.dispatchActivityResult(Activity.java:5390)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     at android.app.ActivityThread.deliverResults(ActivityThread.java:3178)
  09-25 12:01:06.035: E/AndroidRuntime(8783):     ... 11 more
  </code></pre>
  
  <p>My code:</p>
  
  <pre><code>public void onClickEndLabor(View v) {
      if (selectedNextWorkOrderState != null) {
          Intent intent;
  
          if (showNotes) {
              EditText txtNotes = (EditText) findViewById(R.id.txtNotes);
              intent = IntentFactory.createWorkOrderInfo(
                      WorkOrderStateWorkflow.this,
                      selectedNextWorkOrderState, txtNotes.getText()
                              .toString(), Intent.FLAG_ACTIVITY_SINGLE_TOP);
          } else {
              intent = IntentFactory.createWorkOrderInfo(
                      WorkOrderStateWorkflow.this,
                      selectedNextWorkOrderState, "",
                      Intent.FLAG_ACTIVITY_SINGLE_TOP);
          }
  
          setResult(RESULT_OK, intent);
  
          finish();
      }
  }
  </code></pre>
  
  <p>WorkOrderInfo Activity:</p>
  
  <pre><code>protected void onActivityResult(int requestCode, int resultCode,
          Intent intent) {
      if (resultCode == RESULT_OK) {
          super.onActivityResult(requestCode, resultCode, intent);
  
          Bundle extras = intent.getExtras();
          if (extras != null) {
              WorkOrderState nextWOState = (WorkOrderState) extras
                      .getSerializable("workOrderState");
  
              nextState = nextWOState.getWorkOrderState();
              String notes = extras.getString("notes");
              WorkOrder workOrder = Application.getInstance().getWorkOrder();
  
              previousWOState = new WorkOrderState(
                      workOrder.getWorkOrderState(),
                      workOrder.getWorkOrderStateName());
  
              if (Application.getInstance().useLaborRecord()) {
                  lre.setWorkOrder(workOrder);
                  lre.setNotes(notes);
  
                  progress = ProgressDialog.show(this, getResources()
                          .getString(R.string.Wait), getResources()
                          .getString(R.string.EndingLabor));
  
                  if (Application.getInstance().getStatus() == AppStatus.ONLINE) {
                      lre.asyncSave(endHandler);
                      lre.getWorkOrder().offlineSave(false);
                      lre.offlineSave(false, false);
                  } else {
                      if (lre.offlineSave(true, false)
                              &amp;&amp; lre.getWorkOrder().offlineSave(false)) {
                          endHandler.sendEmptyMessage(0);
                      } else {
                          Message msg = new Message();
                          msg.obj = new QueryException(getResources()
                                  .getString(R.string.ErrorSaving));
  
                          endHandler.sendMessage(msg);
                      }
                  }
              } else {
  
                  ChangeWOState changeState = new ChangeWOState(
                          WorkOrderInfo.this);
                  changeState.execute();
  
              }
          }
      }
  }
  </code></pre>
  
  <p>Can someone tell me what is wrong with the code?
  Thank´s for your attention!!!</p>