I have an application where I'm saving int value using datastore preferences , when I get the value , I execute the code and want to return that int value so that I can use it in different places in my code but could not figure it out , if anyone can help , thank you in advance
I tried to make a global member to assign that value and then return but since the value is returned asynchronously , it is crashing the app .
- This is my code
private fun setTextSize() : Int {
val dataStore = requireContext().createDataStore("textSize")
lifecycleScope.launch {
dataStore.data.collect {
val textSize = it[Common.TEXT_SIZE_PREFERENCE]
}
}
}