如何从“OtherClass”中获取“somevariable”的值?正如我在下面尝试的那样,我可以/应该使用 Activity 的上下文吗?
public class ParentActivity extends Activity {
//This variable is reused by multiple Activities inheriting form this class
protected static String somevariable = "text";
...
}
public class MyActivity extends ParentActivity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
myObject = new OtherClass(this);
myObject.doSomething();
...
}
...
}
public class OtherClass(){
private Context c;
private String b;
OtherClass(Context context) {
c = context;
}
doSomething() {
// This does NOT work.
// How can I get somevariable from the ParentActivity????
b = c.somevariable;
}
}