I want to build a method that returns a child value in FireBase. I tried to do something like this:
public String getMessage(){
Firebase usually takes about 1-2 seconds to load the data.
So keeping that in mind you can add a new thread using Handler, to make the system wait for say, 2 Seconds and then use the value retrieved from the Database.
Till then you can display a Loading Dialog box to the user which can be closed once the data is retrieved.
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
{
loadingDialog.dismiss();//dismiss the dialog box once data is retreived
Toast.makeText(Act_NewHome.this, "Not enough players online right now!", Toast.LENGTH_SHORT).show();
tvUserName.setText(u_name);
}
}
}, 2000);// 2000 milliseconds = 2seconds