wait until firebase retrieves data

后端 未结 9 1130
不思量自难忘°
不思量自难忘° 2020-11-29 08:33

I want to build a method that returns a child value in FireBase. I tried to do something like this:

public String getMessage(){

           


        
9条回答
  •  庸人自扰
    2020-11-29 09:03

    You can follow this link https://youtu.be/LVaIArVY52U

    Firebase database is quite slow when retrieving the data so to make the application wait for the process to complete you can follow this

    Create a new class Ex. Firebasedata.java and extent it with Application and add put this code in the OnCreate sections

    public class Firebasedata extends Application {
        @Override
        public void onCreate() {
            FirebaseDatabase.getInstance().setPersistenceEnabled(true);
            super.onCreate();
        }
    }
    

    declare the java class in the manifests

     
    

    Then go back to the class where you want to get the data and create a dialog with this code

        ProgressDialog TempDialog;
        CountDownTimer mCountDownTimer;
        int i=0;
    
            TempDialog = new ProgressDialog(MainActivity.this);
            TempDialog.setMessage("Please wait...");
            TempDialog.setCancelable(false);
            TempDialog.setProgress(i);
            TempDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            TempDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.GRAY));
    
     TempDialog.show();
            mCountDownTimer = new CountDownTimer(2000, 1000)
            {
                public void onTick(long millisUntilFinished)
                {
                    TempDialog.setMessage("Please wait..");
                }
    
                public void onFinish()
                {
                    TempDialog.dismiss();
                    //Your action like intents are placed here
    
                }
            }.start();
    

    You can look into the link above and get a better idea

提交回复
热议问题