My MainActivity begins like this:
class MainActivity : AppCompatActivity() {
val mDBAdapter = DBAdapter(this, "nearbydata")
I want to use the database adapter in another class PickFromList (which extends ListActivity).
I don't seem to be able to refer to it as MainActivity.mDBAdapter. I understand that this is because there are no instances of the MainActivity class.
According to How to reference the current or main activity from another class this is "a problem that lots of developers have". The top answer in that thread reads
If you already have a valid context, just use this: Activity activity = (Activity) context;
Unfortunately to someone as inexperienced as me that is not helpful. How do I know whether I have a valid context? If I don't have one how do I get one?
If I try pasting that code into my PickFromList class, Quick Fix tells me that it "cannot resolve symbol 'context'" and offers to create a local variable 'context'. But that doesn't help.