I have a Map fragment used in my layout, and the layout is inflated to the class extending Fragment.
So I have 2 fragment now
- The Layout
- The Mapfragment
On the App launch I launch this fragment, then on Button click I launch another Fragment.
public void launchFragment(Fragment fragment, String tag)
{
// TODO Auto-generated method stub
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
fragmentTransaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
fragmentTransaction.replace(R.id.container, fragment, tag);
fragmentTransaction.addToBackStack(tag);
fragmentTransaction.commit();
}
But on Back press Map fragment crashes. I have included this code on back press
@Override
public void onBackPressed()
{
// TODO Auto-generated method stub
FragmentManager fm = getSupportFragmentManager();
if (fm.getBackStackEntryCount() > 0)
{
Log.i("MainActivity", "popping backstack");
fm.popBackStack();
}
else
{
Log.i("MainActivity", "nothing on backstack, calling super");
super.onBackPressed();
}
}
Please suggest how to I cope up with this.
I Have attached the screen shot of my full logcat
My XML File
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.winjit.fudtag.BaseAct$PlaceholderFragment" >
<Button
android:id="@+id/xbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="28dp"
android:background="@drawable/button_bg_orange"
android:text="@string/strTag"
android:textColor="@android:color/white"
android:textStyle="bold" />
<Button
android:id="@+id/xbtnSearchMyJunctn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/xbtnTag"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:background="@drawable/button_bg_green"
android:text="@string/strSearchJunctn"
android:textColor="@android:color/white"
android:textStyle="bold" />
<fragment
android:id="@+id/xmapMyloc"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/xbtnSearchMyJunctn"
android:layout_marginTop="30dp" />
</RelativeLayout>