Setting Singleton property value in Firebase Listener

前端 未结 3 1946
挽巷
挽巷 2020-11-21 07:05

I\'m currently testing out Firebase along with a Singleton model I plan to use to access during the lifecycle of the whole app. I\'m now stuck with something that seems real

3条回答
  •  醉酒成梦
    2020-11-21 07:47

    You have to initialize your Singleton when the class is loaded. Put this on your code:

    private static BookSingleton  model = new BookSingleton();
    
    private BookSingleton() {
    }
    
    public static BookSingleton getModel() {     return model == null ? new BookSingleton() : model;
    }
    

提交回复
热议问题