Hi I am developing an app that uses maps.
I am using Fragment Activity and a fragment named Fragment-A.
In Fragment-A there is a button, on clicking that button a Dialog Fragment pops up, displays a map with some location received previously from server.
Let us say this dialog fragment is DialogFragment-B.
It has a button to close, a button to navigate to google maps app to get directions.
If user navigate to DialogFragment-B and returns back to the Fragment-A, by clicking close button every thing is working fine.
But if the user clicks on back button the existing dialog fragment will close normally and the app functions normally.
But if the user then pressed home button or received a phone call and onResume is called even though the DialogFragment-B is dismissed earlier, it reappears and pressing close crashes the app with a null pointer exception
Here is my code to open the DialogFragment-B.
FragmentManager fm = getFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
android.app.Fragment prev = fm.findFragmentByTag(MY_MAP);
if (prev != null) {
ft.remove(prev);
}
MyMapFragmentDialog newFragment = MyMapFragmentDialog
.newInstance(eachPost);
newFragment.show(ft, MY_MAP);
In DialogFragment-B on clicking close button, I call MyMapFragmentDialog.this.dismiss();
Please if any one have encountered this issue and overcame, guide me through.