This is the function I made in one fragment to store my value,
private fun nickdata(){
val sharedPreferences = getSharedPreferences("sharedPrefs", Context.MODE_PRIVATE)
val nicdat = binding.nickname.text.toString()
val editor = sharedPreferences.edit()
editor.putString("Nickname_key","trial")
editor.apply()
editor.commit()}
below is the code I am using to fetch data in another fragment
val pref = activity!!.getPreferences(Context.MODE_PRIVATE)
val id = pref.getString("Nickname_Key", "trial")
binding.nickdata.text = id
In output I am getting "trial" which is def value.