Scenario: I have MainActivity.java , OtherPageForFragments.java and a fragment that is on OtherPageForFragments.java
In MainActivity.java , I wrote the following code to start an action and get the result in
onActivityResult (int requestCode, int resultCode, Intent data)
is an
startActivityForResult(new Intent(this, OtherPageForFragments.class),REQUEST_CODE_MAP);
In the onDestroy() of the fragment class, I wrote this:
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(); }
Now I want to get the result in the MainActivity class. So, I wrote the following code in the onActivityResult method:
if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_CODE_MAP) { tost("2"); double lat=data.getExtras().getDouble("Latitude"); double lng=data.getExtras().getDouble("Longitude"); tost(lat + " -- " + lng); }
Problem: returning resultCode not Activity.RESULT_OK , but Intent I get null .
What to do? Thanks
java android android-intent
P ravikant
source share