How to properly return result from a started activtiy
<p>I have started another activity which I want to return a result to the activity that called it, I have read some tutorial and tried it, but I got some error like this:</p>

<pre><code>08-23 17:48:58.005: E/AndroidRuntime(581): java.lang.RuntimeException: Failure delivering result ResultInfo{who=Tab2, request=0, result=-1, data=Intent { cmp=com.organizer.medical.activities/.AddPatientActivity (has extras) }} to activity {com.organizer.medical.activities/com.organizer.medical.activities.Main}: java.lang.NullPointerException
08-23 17:48:58.005: E/AndroidRuntime(581):  at android.app.ActivityThread.deliverResults(ActivityThread.java:2980)
08-23 17:48:58.005: E/AndroidRuntime(581):  at android.app.ActivityThread.handleSendResult(ActivityThread.java:3023)
08-23 17:48:58.005: E/AndroidRuntime(581):  at android.app.ActivityThread.access$1100(ActivityThread.java:123)
08-23 17:48:58.005: E/AndroidRuntime(581):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1177)
08-23 17:48:58.005: E/AndroidRuntime(581):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-23 17:48:58.005: E/AndroidRuntime(581):  at android.os.Looper.loop(Looper.java:137)
08-23 17:48:58.005: E/AndroidRuntime(581):  at android.app.ActivityThread.main(ActivityThread.java:4424)
08-23 17:48:58.005: E/AndroidRuntime(581):  at java.lang.reflect.Method.invokeNative(Native Method)
08-23 17:48:58.005: E/AndroidRuntime(581):  at java.lang.reflect.Method.invoke(Method.java:511)
08-23 17:48:58.005: E/AndroidRuntime(581):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
08-23 17:48:58.005: E/AndroidRuntime(581):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
08-23 17:48:58.005: E/AndroidRuntime(581):  at dalvik.system.NativeStart.main(Native Method)
08-23 17:48:58.005: E/AndroidRuntime(581): Caused by: java.lang.NullPointerException
08-23 17:48:58.005: E/AndroidRuntime(581):  at com.organizer.medical.activities.PatientActivity.onActivityResult(PatientActivity.java:347)
08-23 17:48:58.005: E/AndroidRuntime(581):  at android.app.ActivityGroup.dispatchActivityResult(ActivityGroup.java:122)
08-23 17:48:58.005: E/AndroidRuntime(581):  at android.app.ActivityThread.deliverResults(ActivityThread.java:2976)
08-23 17:48:58.005: E/AndroidRuntime(581):  ... 11 more
</code></pre>

<p>Here is my code for the calling activity:</p>

<pre><code>@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 0) {
      if (resultCode == RESULT_OK) {
        int cat = Integer.parseInt(getIntent().getExtras().get("category").toString());
        loadList(cat);
       }
 }
}
</code></pre>

<p>This is on my oncreate() on my calling activity: </p>

<pre><code>startActivityForResult(new Intent(this, CalledActivity.class), ADD_PATIENT);
</code></pre>

<p>This is my code for the "called" activity: </p>

<pre><code>   setResult(RESULT_OK, getIntent().putExtra("category", status.isChecked()?1:2));
   finish();
</code></pre>

<p>By the way on my called activity the <code>setResult()</code> and <code>finish()</code> is done only <code>onClick</code> by a button on that called activity... </p>

<p>I really don't know how to properly use <code>startActivityForResult()</code>. Please do share your knowledge about this.</p>

<p>UPDATE</p>

<hr>

<p>Turns out that the intent that i'm accessing on onActivityResult() is causing the null exception error and turns out that the "date" var passed on that method is the one to be used as such: </p>

<pre><code>int cat = Integer.parseInt(**data**.getExtras().get("category").toString());
</code></pre>
