Communicative Between Fragments on Android

后端 未结 5 1553
日久生厌
日久生厌 2021-01-21 19:21

I am attempting to build an Android application that has two tabs, one for a textField/button and TreeMenu (where each element has a checkbox associated with it) and another for

5条回答
  •  旧巷少年郎
    2021-01-21 19:36

    A singleton class could help solve your problem.

    public class GlobalApp {
        private static GlobalApp instance = new GlobalApp();
    
        private GlobalApp() {}
    
        public static GlobalApp getInstance() {
            return instance;
        }
    
        public ArrayList < ClassName > varName = new ArrayList < ClassName > ();
    
    }
    

    Then use in your class like this..

    GlobalApp.getInstance().varName
    

提交回复
热议问题