Access of static variables from one class to another in Android : I'm having a hard time trying to understand static variables. Can anybody explain why when I call the variable 'startingDate' in FragmentJoy, it doesn't return the correct value? Assume all the rest of the code is working perfectly, not NULL values and databaseCategories is working fine. How can I save a value inside 'onDataChange()' method and use it in FragmentJoy? 

I CANNOT remove: 
    
    @Nullable
        @Override
        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {)


   This is dashboard activity

    public class Dashboard extends AppCompatActivity
        implements NavigationView.OnNavigationItemSelectedListener {

    static String startingDate;
    DatabaseReference databaseCategories;
    ArrayList<Category> currentJoyCategories;


    User currentUser; //holds the information of the current user


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_dashboard);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        . . . . . .

        databaseCategories = FirebaseDatabase.getInstance().getReference("Categories");

        currentJoyCategories = new ArrayList<>();

        databaseCategories.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                    
                   //want to do
                   startingDate = "some string";
             }

             @Override
            public void onCancelled(DatabaseError databaseError) {

            }
        });
    } //end of Dashboard class


In Another class I want to do:

    public class FragmentJoy extends Fragment {
        
        @Nullable
        @Override
        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.fragment_joy,container,false);

             //not storing the string "some string"
            System.out.println("testing " + Dashboard.startingDate);

    } //end of onCreateView method
    } //end of class
