Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android-Live-Shared-Preferences-Gist5
class MainActivity : AppCompatActivity() {
private const val TAG = "MainActivity"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val preferences = PreferenceManager.getDefaultSharedPreferences(this)
val liveSharedPreferences = LiveSharedPreferences(preferences)
liveSharedPreferences.getString("exampleString", "default").observe(this, Observer<String> { value ->
Log.d(TAG, value)
})
liveSharedPreferences.getInt("exampleInt", 0).observe(this, Observer<Int> { value ->
Log.d(TAG, value.toString())
})
liveSharedPreferences.getBoolean("exampleBoolean", false).observe(this, Observer<Boolean> { value ->
Log.d(TAG, value.toString())
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.