I normally do Windows/C#/C++ programming but I dabble in Android so I've been asked to look at Android program to fix a bug in it. I do not have a mandate to re-architect it, so what's static stays static.
The problem is this: In one Activity it has a public static method. It also has all the usual non-static methods. There's one instance of this particular Activity class.
I want to be able to call some non-static methods on this Activity class and access some of its data from the static method. Obviously if I try to do so directly I get,
Cannot make a static reference to the non-static method ...
I assume there must be a way to stash some reference to that specific instance of Activity class in some global public place during the onStart() or onCreate() methods using this or some context, and then use that in the static method to make the calls, e.g.,
myStoredClassInstance.aNonStaticMethod();
...but I don't know the syntax. Can anyone help me out on this?
PS Before you say this is a duplicate of this: calling non-static method in static method in Java note that that question is about calling a non-static method of a separate class, so the answers involved creating a new instance of that class on the fly. In my case I want to know the syntax of accessing an existing specific class.