Skip to content

Instantly share code, notes, and snippets.

@ibrahimsn98
Last active January 1, 2019 09:56
Show Gist options
  • Select an option

  • Save ibrahimsn98/741a7ecacd8737f41f0dba690e071ee6 to your computer and use it in GitHub Desktop.

Select an option

Save ibrahimsn98/741a7ecacd8737f41f0dba690e071ee6 to your computer and use it in GitHub Desktop.
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