【发布时间】:2015-11-18 18:42:00
【问题描述】:
尝试旋转设备后出现此异常:
java.lang.IllegalStateException: Activity has been destroyed.
在我的OnCreate() 我做的很简单:
FragmentTransaction fragTx = FragmentManager.BeginTransaction();
_myMapFragment = MapFragment.NewInstance(mapOptions);
fragTx.Replace(Resource.Id.map, _myMapFragment, "map");
fragTx.Commit();
我也在尝试删除 OnDestroy() 中的 mapfragment,如下所示:
FragmentTransaction fragTx = FragmentManager.BeginTransaction();
fragTx.Remove(_myMapFragment);
fragTx.CommitAllowingStateLoss();
提前感谢您对此问题的任何帮助。
这是我的Main.axml 的样子:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@id/toolbar">
<AutoCompleteTextView
android:hint="Nazwa ulicy w Warszawie"
android:id="@+id/txtTextSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:imeOptions="actionSearch"
android:imeActionId="@+id/txtTextSearch"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
</LinearLayout>
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
class="com.google.android.gms.maps.MapFragment" />
<Button
android:text="Moja lokalizacja"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:id="@+id/btnLocalizeMe"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="@android:color/holo_orange_dark" />
还有我MainActivity的标题:
public class MainActivity : AppCompatActivity,
GoogleApiClient.IConnectionCallbacks,
GoogleApiClient.IOnConnectionFailedListener,
ILocationListener
【问题讨论】:
-
看看这个post
-
请更新完整的跟踪日志,有助于追踪您遇到的问题?
标签: android android-fragments xamarin xamarin.android