【发布时间】:2016-07-12 10:55:40
【问题描述】:
我有一个基于 NavigationDrawer 的应用程序。我加载的片段之一包含一个 GoogleMap 片段。
这是用来加载片段的
getSupportFragmentManager().beginTransaction().replace(R.id.container,
new MyMapFragment()).addToBackStack("mytag1").commit();
页面加载没有任何问题并显示地图。但是当我使用菜单切换到另一个片段并按返回按钮时,应用程序崩溃。该片段仅包含加载地图的最少代码。
片段 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()); }
}
上面的 Catch 不会触发。 Logcat 在第 125 行说 inflate 异常,这是放置地图片段的位置。
我真的很感激任何帮助...
我正在添加我当前的测试条件和工作环境以防万一
AndroidStudio 2.1 最小 SDK 版本 10 目标 SDK 版本 24 编译 SDK Ver 24
在运行 Android 6.0.1 的 Nexus 6 上进行测试
【问题讨论】:
-
onCreateView方法在返回 Fragment 时是否被调用? -
@ρяσѕρєя K 是的,当我按下返回按钮时,会再次调用 onCreateView。
标签: android google-maps-android-api-2 inflate-exception