Hi, I am developing an application that uses maps.
I am using Fragment Activity and a fragment called Fragment-A.
In Fragment-A there is a button, when you click this button, a fragment of the dialog opens, a map with a certain location obtained earlier from the server is displayed.
Say this piece of dialogue is DialogFragment-B.
It has a button to close, a button to go to the Google Maps app to get directions.
If the user goes to DialogFragment-B and returns to fragment-A by pressing the close button, everything works fine.
But if the user presses the "Back" button, the existing fragment of the dialog closes normally, and the application functions normally.
But if the user pressed the home button or received a phone call, and onResume is called even if DialogFragment-B is fired earlier, it appears again and pressing the button closes the application with an exception with a null pointer
Here is my code to open 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, when I click the close button, I call MyMapFragmentDialog.this.dismiss ();
Please, if someone ran into this problem and won, guide me through.