Android Firebase - setPersistenceEnabled(true) crashing the app

前端 未结 5 1524
伪装坚强ぢ
伪装坚强ぢ 2021-01-25 01:00

So I was just trying out Firebase to update Toolbar label of activities from realtime database. I am getting the following error:

12-21 00:25:19.890 10295-10295/         


        
5条回答
  •  独厮守ぢ
    2021-01-25 01:59

    You can use a Model class and use Method inside it such as the one mentioned below.

    public class DatabaseUtility {
    
        private static FirebaseDatabase database;
    
        public static FirebaseDatabase getDatabase(){
            if(database==null){
                database=FirebaseDatabase.getInstance();
                database.setPersistenceEnabled(true);
            }
            return database;
        }
    }
    

    This will return database instance and you can use database.getReference(); method to get Root reference. This will also save some time if the database object is already present.

提交回复
热议问题