I'm trying to save uuid in application memory. To do this I perform to use Shared Preferences and use this guide from developer.android.com From this place exactly PLACE
private fun setPreferences(response: JSONObject) {
val sharedPref = this.getPreferences(Context.MODE_PRIVATE) ?: return
with(sharedPref.edit()) {
putString(
getString(R.string.PREFERENCE_FILE_KEY),
response.get("uuid").toString()
)
apply()
}
This is my strings.xml file
<resources>
<string name="app_name">Book of recipes</string>
<string name="prompt_login">Login</string>
<string name="prompt_password">Password</string>
<string name="prompt_confirm_password">Confirm password</string>
<string name="action_sign_in_short">Sign in</string>
<string name="have_an_account">Already have an account?</string>
<string name="dont_have_an_account">Don\'t have an account?</string>
<string name="rabbits_with_carrots">Rabbits with carrots</string>
<string name="login_error">Login must be 4–12 characters long</string>
<string name="password_error">Password must be 4–16 characters long</string>
<string name="password_error_reconciliation">Wrong password re-entered</string>
<string name="characters_check_error">Field contains invalid characters</string>
<string name="PREFERENCE_FILE_KEY"></string>
</resources>
After some tries to understand why this isn't working I write this lines of code in my setPreference fun
println("UUID : " + response.get("uuid").toString())
println("Preference file key : " + getSharedPreferences(
getString(R.string.PREFERENCE_FILE_KEY), Context.MODE_PRIVATE))
println("R string : " + applicationContext.getString(R.string.PREFERENCE_FILE_KEY))
And take as response this :
I/System.out: UUID : 2c912ffb-01c0-430f-91ca-4ebe7d663225
I/System.out: Preference file key : android.app.SharedPreferencesImpl@638299c
R string :
So question , why I take this result when I trying to get shared preferences and how I can put this uuid in strings.xml file and take it back?