I have a main Activity and a Dialog through which I would like to change some application variables. This unfortunately includes changing the properties of existing instances of several different classes. What I would like to do is call a method of my main Activity that would handle both changing the Activity’s variables and modifying existing instances of classes. In my Dialog I call
mainActivity.smartSetter(variableName, variableValue);
and in my Activity I have
public void smartSetter(variableName name, float value) {
switch (name) {
case Name1: {do stuff}
case Name2: {do stuff}
//etc
}
The compiler says that I Cannot make a static reference to the non-static method smartSetter. Being still a Java noob, I suspect it is because the smartSetter needs to be called on an instance of mainActivity, not just the class itself. Could someone please clarify?
Also, this problem seems to be caused by poor design of the application architecture, so I welcome any suggestions that would help me improve the design so that it would be more usable and elegant.
Maybe this
smartSettershould be implemented as a Broadcast Receiver. I think this example fits your needs.