我有一个基于NavigationDrawer的应用程序。我加载的片段之一包含GoogleMap片段。地图片段在使用后退按钮输入时崩溃
这是什么,是用来加载片段
getSupportFragmentManager().beginTransaction().replace(R.id.container,
new MyMapFragment()).addToBackStack("mytag1").commit();
该页面加载,没有任何问题,并显示map.But然后当我用菜单切换到另一个片段,然后按返回键,应用程序崩溃。该片段仅包含加载地图的最少代码。
片段XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ll_report_in_out"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical"
tools:context="my.package.name" >
<LinearLayout
android:id="@+id/llv_layer2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
>
<!-- some content -->
</LinearLayout>
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
class="com.google.android.gms.maps.SupportMapFragment"
android:name="my.package.name.MyMapFragment"
/>
</LinearLayout>
活动:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_report_in_out, container, false);
try {
fm = ((SupportMapFragment) getChildFragmentManager()
.findFragmentById(R.id.map));
if (fm != null)
map = fm.getMap();
else
map = null;
}
catch(Exception e)
{ Log.i("dbg",e.toString()); }
}
渔获以上不火。 Logcat在线125上说膨胀异常,这是放置地图片断的地方。
我真的很感激任何帮助......
我加入我目前的测试条件和工作环境的情况下,它的事项
AndroidStudio 2.1 敏SDK版本10 目标SDK版本24 编译SDK版本24
测试Nexus 6上运行的是Android 6.0.1
回复on Fragment时会调用'onCreateView'方法吗? –
@языкK是当我按下后退按钮时,再次调用onCreateView。 – Deepak