Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android-Live-Shared-Preferences-Git1
class MainActivity : AppCompatActivity() {
private val preferences = PreferenceManager.getDefaultSharedPreferences(this)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
var listener: SharedPreferences.OnSharedPreferenceChangeListener =
SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
when (key) {
"myKey1" ->
"myKey2" ->
}
}
override fun onResume() {
super.onResume()
preferences.registerOnSharedPreferenceChangeListener(listener)
}
override fun onPause() {
super.onPause()
preferences.unregisterOnSharedPreferenceChangeListener(listener)
}
}
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.