An easy way that I implemented is savaing the data first in a in lists and then in a SQLite database:
if (db != null) {
for (int x = 0; x < latitud.size(); x++) {
newReg.put("ID", x);
newReg.put("Latitude", latitude.get(x));
newReg.put("Longitude", longitude.get(x));
db.insert("Records", null, newReg);
}
} else{
Toast.makeText(MainActivity.this, "Error",Toast.LENGTH_SHORT).show();
}
db.close();
private void getLatLgns() {
DBConnection dbc = new DBConnection(this, "MapsDB", null, 1);
SQLiteDatabase db = dbc.getWritableDatabase();
Cursor c = db.rawQuery("SELECT Latitude,Longitude from Records", null);
if(c.moveToFirst()){
do {
allLatLng.add(new LatLng(Double.parseDouble(c.getString(0)), Double.parseDouble(c.getString(1))));
}while (c.moveToNext());
}
db.close();
}
If you don't know how to use SQLite just look for some info on internet, is pretty easy and there's a lot of examples.