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);**
}
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.