Read / Write Configuration Information using Preferences


  • Preferences


  • Android smartphone or emulator

Android provides several options for you to save persistent application data. SharedPreferences provides a general framework that allows you to save and retrieve persistent key-value pairs of primitive data types. You can use SharedPreferences to save any primitive data: booleans, floats, ints, longs, and strings. This data will persist across user sessions (even if your application is killed).

Run the to save the value and subsequent running of will retrieve the stored value.

import android droid = android.Android() putstoreval = droid.dialogGetInput('Store Value').result print putstoreval droid.prefPutValue("mystoreval",putstoreval,"mypref.txt")

putstoreval is assigned to the key mystoreval and stored in the preferences file mypref.txt

import android droid = android.Android() getstoreval = droid.prefGetValue("mystoreval","mypref.txt").result print getstoreval

More information about the preferences api

Scan the script to your smartphone using the Test EMANT380 app or download to PC/Emulator