I am trying to save user preferences for language, so I have a preferences class with a setter and getter for language, as well as a separate Language activity where the user actually picks which language they want.
From this language activity, I want to use the setter to set the user's chosen language preference within the preferences class. Here is the preferences class:
class Preferences (context: Context) {
val PREFS_FILENAME = "artour.prefs"
val LANGUAGE = "language"
val prefs: SharedPreferences = context.getSharedPreferences(PREFS_FILENAME, Context.MODE_PRIVATE);
fun getLang() : String {
return prefs.getString(LANGUAGE, "english")
}
public fun setLang(lang:String) {
val editor = prefs.edit()
editor.putString(LANGUAGE, lang)
editor.apply()
}
}
How would I go about running the setLang method from the language activity?