我有一個基於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