0

is there anyone here that is using a fragment container to show the MapFragment at runtime?

I have some issues with this implementation. If I replace the MapFragment with another FragmentActivity and popbackstack it. The Map view is not showing and it is in black.

Here is my Layout:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />

    <LinearLayout
        android:id="@+id/main_frame_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"/>

</LinearLayout>

My Activity source code:

public void onCreate(Bundle savedInstanceState) {
.....

final String MAP_TAG = "map_tag";
mapFragment = new MapFragment();
            getFragmentManager().beginTransaction().add(R.id.main_frame_layout, mapFragment,
                    MAP_TAG)
                    .commit();
....

setContentView(R.layout.activity_main);

}


@Override
    protected void onPause() {
        super.onPause();
        if(map != null)
            mapFragment.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        if(map != null)
            mapFragment.onResume();
    }


    @Override
    public void onBackPressed() {
        Log.d("Test","onBackPressed");

        if( getFragmentManager().getBackStackEntryCount() == 0) {
            Log.d("Test","pop back stack finish");
            finish();
        } else {
            Log.d("Test","pop back stack");
            getFragmentManager().popBackStack();
        }
        Log.d("Test","remaining in stack " + getFragmentManager().getBackStackEntryCount());

    }
neilQ5
  • 179
  • 1
  • 12

1 Answers1

0

Maybe the map is null when you call onResume() ? Or perhaps the frament has no size? Generally the black screen indicates no layout or the view was not resumed correctly.

@Override
protected void onResume() {
    super.onResume();
    if(map != null)
        mapFragment.onResume();
}
David Leong
  • 1,662
  • 1
  • 11
  • 7