I am getting this exception after trying to rotate device:
java.lang.IllegalStateException: Activity has been destroyed.
In my OnCreate()
I am doing simple:
FragmentTransaction fragTx = FragmentManager.BeginTransaction();
_myMapFragment = MapFragment.NewInstance(mapOptions);
fragTx.Replace(Resource.Id.map, _myMapFragment, "map");
fragTx.Commit();
and I am also trying to remove mapfragment in my OnDestroy()
, like this:
FragmentTransaction fragTx = FragmentManager.BeginTransaction();
fragTx.Remove(_myMapFragment);
fragTx.CommitAllowingStateLoss();
Thanks in advance for any help with this issue.
Here is how my Main.axml
looks like:
<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" />
And header of my MainActivity
:
public class MainActivity : AppCompatActivity,
GoogleApiClient.IConnectionCallbacks,
GoogleApiClient.IOnConnectionFailedListener,
ILocationListener