I am trying to use the latest Map API 2.0 provided for Android. I am using the Support Library as I want to support Android 2.2. Following is my code:
Main A
You can fix this, if you delete all nested fragments in onDestroyView()
. Don't know if it is a proper solution.
public void onDestroyView() {
super.onDestroyView();
Fragment fragment = (getFragmentManager().findFragmentById(R.id.map));
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.remove(fragment);
ft.commit();
}
And inflating them as usual in onCreateView()
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.map, container, false);
}
Use dialog.SetContentView()
method in your activity's onCreate()
cause when we tring to load.
Dialog again it loads only dialog not the whole activity life cycle and leads it to exception of Duplicate id.
Try it.
I used Natalia response but at times broke the application. Use this one and it worked perfectly without breaking.
@Override
public void onDestroyView() {
try{
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.remove(nestedFragment);
transaction.commit();
}catch(Exception e){
}
super.onDestroyView();
}
https://stackoverflow.com/a/7953801/3364157
Used this solution (similar to others):
public void onDestroyView() {
FragmentManager fm = getActivity().getSupportFragmentManager();
Fragment fragment = (fm.findFragmentById(R.id.map));
if (fragment.isResumed()) {
FragmentTransaction ft = fm.beginTransaction();
ft.remove(fragment);
ft.commit();
}
super.onDestroyView();
}
I had problems before using the if (fragment.isResumed).
You need to use getChildFragmentManager() to add SupportMapFragment not not through xml.
For "why", see official documentation: http://developer.android.com/about/versions/android-4.2.html#NestedFragments
Take a look at my answer here: https://stackoverflow.com/a/15512285/2183804