Обычно я использую код A или код B для чтения или записи SharedPreferences.
В настоящее время я обновляю свой проект, чтобы использовать "androidx.preference:preference-ktx:1.1.1"
с Kotlin.
Есть ли лучший способ читать и писать SharedPreferences, когда я использую "androidx.preference:preference-ktx:1.1.1"
с Kotlin?
Код А
SharedPreferences prfs = getSharedPreferences("AUTHENTICATION_FILE_NAME", Context.MODE_PRIVATE);
String Astatus = prfs.getString("Authentication_Status", "");
Код Б
SharedPreferences preferences = getSharedPreferences("AUTHENTICATION_FILE_NAME", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("Authentication_Id",userid.getText().toString());
editor.putString("Authentication_Password",password.getText().toString());
editor.putString("Authentication_Status","true");
editor.apply();