I use following method to get var from another class. However, firstView receives always null value. Why? Thanks
Main class
private String view1 = null;
//...when onCreate view1 is checked that set properly
public String getView1() {
return view1;
}
second class
TabBar_Activity mainRef = new TabBar_Activity();
firstView = mainRef.getView1();
Right behavior because when you getView using
getView1()method you are creating newmainRefobject ofTabBar_Activity. And in that you have just declaredString view1 = null. If you want to get setter view1 value then use the object which you are using for setter view1 value inonCreate()of activity not new object.