Last active
January 1, 2019 09:56
-
-
Save ibrahimsn98/741a7ecacd8737f41f0dba690e071ee6 to your computer and use it in GitHub Desktop.
Android-Live-Shared-Preferences-Gist5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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