Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The first part of my implementation consists of declarations that define the keys used to retrieve the Shared Preferences and of course the variables that they CAN be stored into. The first routine is to initialize the Shared Preferences (in order to load the shared preferences, u need to have values in the code to save so u need some code to initialize these values in the code). The second routine is to save the Shared Preferences. The third routine is to load the Shared Preferences.</p> <p>This is the key definition part</p> <pre><code>private SharedPreferences sharedPreferences; public final static String MARV_INIT = "MARV_INIT"; public final static String MARV_LAT = "MARV_LATITUDE"; public final static String MARV_LON = "MARV_LONGITUDE"; public final static String MARV_ZOOM = "MARV_ZOOM"; public final static String MARV_PDFL = "MARV_PDFL"; public final static String MARV_PRON = "MARV_PRON"; public final static String MARV_LTRD = "MARV_LTRD"; </code></pre> <p>And here are the 3 routines.</p> <pre><code>// Shared Preferences and other data loading routines for this activity private void initSharedPreferences() { Log.i(TAG, "Initializing shared preferences ..."); Editor editor = sharedPreferences.edit(); editor.putInt(MARV_INIT, 1); editor.putString(MARV_LAT, ((Double) SG_LATITUDE).toString()); editor.putString(MARV_LON, ((Double) SG_LONGITUDE).toString()); editor.putFloat(MARV_ZOOM, (float) DEFAULT_ZOOM); editor.putString(MARV_PDFL, getString(R.string.default_poi_list)); editor.putBoolean(MARV_PRON, true); editor.putFloat(MARV_LTRD, (float) LocationAlertService.DEFAULT_RADIUS); editor.commit(); } private void saveSharedPreferences() { // Update global variables first updateCameraProperties(); // Now save global variables into shared preferences Editor editor = sharedPreferences.edit(); editor.putString(MARV_LAT, ((Double) lastCameraPosition.latitude).toString()); editor.putString(MARV_LON, ((Double) lastCameraPosition.longitude).toString()); editor.putFloat(MARV_ZOOM, lastCameraZoom); editor.putString(MARV_PDFL, poiDocFileListUrl); editor.putBoolean(MARV_PRON, proximityAlertsOn); editor.putFloat(MARV_LTRD, lastRadiusUsed); editor.commit(); } private void loadSharedPreferences() { lastCameraPosition = new LatLng(Double.parseDouble(sharedPreferences .getString(MARV_LAT, ((Double) SG_LATITUDE).toString())), Double.parseDouble(sharedPreferences.getString(MARV_LON, ((Double) SG_LONGITUDE).toString()))); lastCameraZoom = sharedPreferences.getFloat(MARV_ZOOM, DEFAULT_ZOOM); poiDocFileListUrl = sharedPreferences.getString(MARV_PDFL, getString(R.string.default_poi_list)); proximityAlertsOn = sharedPreferences.getBoolean(MARV_PRON, true); lastRadiusUsed = sharedPreferences.getFloat(MARV_LTRD, LocationAlertService.DEFAULT_RADIUS); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload