I have a list of CustomClass and a function which returns this list in their own kotlin file. The function is only ever called from MainActivity but since it is not in the same file I cannot pass context when building the list.
In the custom class definition I want to access a variable in shared preferences, but to do this I need a context, which would be MainActivity. So my question is how do I grab MainActivities context from elsewhere, or is there another way to access shared preferences?
The custom class contains:
open class ListItems(
open val title: String,
...
)
class GameName(
override val title: String,
...
) : ListItems(title, active) {
init {
val context: Context = MainActivity::class
val savedData = context.getSharedPreferences("CompletedGames", Context.MODE_PRIVATE)
...
}
}