I\'m trying to applicate drawernavigation (my first fragment is a map & the others are just some fragments with simple layouts).So it runs fine & I can navigate betw
I think you have to try to retrieve old Fragments instance instead of recreating it each time a drawer item is selected. In your displayView method of LoginScreen Activity, you have to do something like that in the switch:
Fragment fragment = null;
String title = getResources().getString(SOME_FRAGMENT_TITLE);
switch (position) {
case 1:
fragment = (YourFragment) fm.findFragmentByTag(title);
if (fragment == null) fragment = new YourFragment();
break;
}
use this
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
/>
and override method onDestroyView()
and Just put this code in onDestroyView()
public void onDestroyView()
{
super.onDestroyView();
Fragment fragment = (getFragmentManager().findFragmentById(R.id.map));
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.remove(fragment);
ft.commit();
}
Try to reuse/recycle your layout. I am running into "duplicate id" when using a map fragment. So in onCreateView instead of
final View rootView = inflater.inflate(R.layout.fragment_profile, container, false);
i am using
public class YourFragment extends Fragment {
public YourFragment(){}
...
private static View rootView;
...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//View rootView = inflater.inflate(R.layout.fragment_layout, container, false);
if (rootView != null) {
ViewGroup parent = (ViewGroup) rootView.getParent();
if (parent != null)
parent.removeView(rootView);
}
try {
rootView = inflater.inflate(R.layout.fragment_layout, container, false);
} catch (InflateException e) {
/* map is already there, just return view as it is */
}