Domanda

I was looking for this - but found only how to save an arrayList for example this code:

 Editor prefsEditor = mPrefs.edit();
 Gson gson = new Gson();
 String json = gson.toJson(MyObject);
 prefsEditor.putString("MyObject", json);
 prefsEditor.commit();

I want to store this object(point) which is LatLng in SharedPreferences, after that i will need to get it from this save. Here is what i want to save:

public void onMapClick(LatLng point) {
    // TODO Auto-generated method stub

    mMap.addMarker(new MarkerOptions().position(point));
    **checkPoints.add(point);**
}
È stato utile?

Soluzione

Instead of using preferences you can use Sqlite database. But if you insist on using SharedPreferences then I don't think you have much choice as you can only store boolean, float, int, long, String or StringSet. The only possible way I see is that you concatenate all of the values with your own separator like

1123.4456:1234.223|1123.4456:1234.1233|1123.4456:1234.223|1123.4456:1234.223

and then just parse when retrieving it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top