Error opening SupportMapFragment for second time
Instead of declaring de SupportMapFragment in layout, do it programatically and be sure you use getChildFragmentMananger instead of the classic getFragmentManager() to create the fragment.
mMapFragment = SupportMapFragment.newInstance();
FragmentTransaction fragmentTransaction =
mMapFragment.getChildFragmentManager().beginTransaction();
fragmentTransaction.add(R.id.map_root, mMapFragment);
fragmentTransaction.commit();
Keep this SupportMapFragment mMapFragment as you will need it to retrieve the GoogleMap object:
GoogleMap map = mMapFragment.getMap();
SherlockFragment which contains SupportMapFragment does not open second time
You are incorrectly adding SupportMapFragment
into your fragment.
Please read about nested fragments.
When nesting fragments remember these things:
- use
getChildFragmentManager
, - don't add
SupportMapFragment
in xml.
SupportMapFragment show for second time
There is a similar known issue, look here
This is a bug in the nested fragments. Basically, the child FragmentManager ends up with a broken internal state when it is detached from the activity.
A short-term workaround is to add the following code in your fragment.
@Override
public void onDetach() {
super.onDetach();
try {
Field childFragmentManager = Fragment.class.getDeclaredField("mChildFragmentManager");
childFragmentManager.setAccessible(true);
childFragmentManager.set(this, null);
} catch (NoSuchFieldException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
Related Topics
Streaming Video from Android Camera to Server
How to Resize a Custom View Programmatically
Navigationview Onnavigationitemselectedlistener Not Being Called
How to Connect Android App to MySQL Database
Android - Java.Lang.Securityexception: Permission Denial: Starting Intent
Broadcastreceiver Not Receiving Boot_Completed
How to Clear a Notification in Android
Android. Fragment Getactivity() Sometimes Returns Null
Is It a Bad Practice to Use Negative Margins in Android
Reference One String from Another String in Strings.Xml
Capturing Mobile Phone Traffic on Wireshark
How Does One Use Glide to Download an Image into a Bitmap
How to Put Multiple Project_Number/Sender Id in Google-Services.JSON
Counting Chars in Edittext Changed Listener
Error Opening Trace File: No Such File or Directory (2)