title: Android: setResult not working
body: <p>Scenario: I have a <code>MainActivity.java</code>, <code>OtherPageForFragments.java</code> and a fragment which is on <code>OtherPageForFragments.java</code></p>
  
  <p>In <code>MainActivity.java</code>, I have written the following code to start an activity and get result in </p>
  
  <blockquote>
    <p>onActivityResult(int requestCode, int resultCode, Intent data)</p>
  </blockquote>
  
  <p>is</p>
  
  <pre><code>startActivityForResult(new Intent(this, OtherPageForFragments.class),REQUEST_CODE_MAP);
  </code></pre>
  
  <p>In the <code>onDestroy()</code> of the fragment class, i have written this:</p>
  
  <pre><code>public void onDestroyView() {
          // TODO Auto-generated method stub
          super.onDestroyView();
          mlocManager.removeUpdates(this);
          Intent intent = new Intent();
          intent.putExtra("Latitude", passLatLng.latitude);
          intent.putExtra("Longitude", passLatLng.longitude);
          getActivity().setResult(Activity.RESULT_OK, intent);
          getActivity().finish();
      }
  </code></pre>
  
  <p>Now, I want my result in the <code>MainActivity</code> class. So, i have written the following code in the <code>onActivityResult</code> method:</p>
  
  <pre><code>if (resultCode == Activity.RESULT_OK &amp;&amp; requestCode == REQUEST_CODE_MAP)
          {
              tost("2");
              double lat=data.getExtras().getDouble("Latitude");
              double lng=data.getExtras().getDouble("Longitude");
              tost(lat + " -- " + lng);
          }
  </code></pre>
  
  <p>The Problem: the <code>resultCode</code> getting returned is not <code>Activity.RESULT_OK</code> and the <code>Intent</code> I am getting is <code>null</code>.</p>
  
  <p>What to do? Thanks</p>