SupportMapFragmentを拡張するクラスがあり、バックエンドからデータをロードしてマーカーを表示します。マップ上で選択したマーカーに対応する詳細を表示する別のフラグメントもあります。地図の下に縦向きモードで詳細フラグメントを表示し、横向きで並べて表示しています。
public class MapDisplayFragment extends SupportMapFragment {
private ArrayList<ShowLocation> locations = null;
public void onViewCreated(View view, Bundle savedInstanceState) {
if (savedInstanceState != null) {
locations = (ArrayList<ShowLocation>)savedInstanceState.getSerializable("LOCATIONS");
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
if (outState == null) {
outState = new Bundle();
}
outState.putSerializable("LOCATIONS", locations);
super.onSaveInstanceState(outState);
}
派生マップクラスで使用されるSerializableを実装するクラスがあります。onSaveInstanceStateを使用してオブジェクトを保存しているので、バックエンドからデータを再度取得する必要はありません。しかし、アプリはjava.lang.RuntimeExceptionでクラッシュします。デバイスを反転すると、ParcelableがSerializableオブジェクトを読み取ってClassNotFoundExceptionが発生しました。
public class ShowLocation implements Serializable {
private String geoCodeLat = Constants.EMPTY_STRING;
private String geoCodeLng = Constants.EMPTY_STRING;
....
public String getGeoCodeLat() {
return geoCodeLat;
}
public void setGeoCodeLat(String geoCodeLat) {
this.geoCodeLat = geoCodeLat;
}
public String getGeoCodeLng() {
return geoCodeLng;
}
public void setGeoCodeLng(String geoCodeLng) {
this.geoCodeLng = geoCodeLng;
}
....
}
レイアウトを次のように定義しました。
<LinearLayout
android:id="@+id/layoutMapData"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/mapFrag"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.5"
class="com.test.appFragments.MapDisplayFragment" />
<LinearLayout
android:id="@+id/layoutDetails"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.5"
android:visibility="gone" >
</LinearLayout>
</LinearLayout>
誰かがこの問題に遭遇した場合、またはこの問題の解決策がある場合は、私を助けてください。