3

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

  1. The Layout
  2. 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 Crash Logs Crash Logs

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>
Trideep
  • 396
  • 1
  • 2
  • 15
  • The error is probably in your layout XML, please add layout XML – EpicPandaForce Mar 20 '15 at 10:30
  • Try the answer in this question, i think it will help you: http://stackoverflow.com/questions/14083950/duplicate-id-tag-null-or-parent-id-with-another-fragment-for-com-google-androi – Rubén Jiménez Mar 20 '15 at 11:51
  • it will only work if the fragment is back stacked but if we want to relaunch the fragment. it shows blank fragment – Trideep Mar 20 '15 at 12:42

0 Answers0