Java tutorial
//package com.java2s; import android.content.Context; import android.content.SharedPreferences; import java.util.HashMap; public class Main { public static HashMap<String, String> restoreDistanceAndLocation(Context context) { SharedPreferences sharedPref = context.getSharedPreferences("DistanceAndLocation", Context.MODE_PRIVATE); String[] keyList = { "longitude", "latitude", "kmTravelled" }; HashMap<String, String> values = new HashMap<>(); for (String key : keyList) values.put(key, sharedPref.getString(key, null)); return values; } }