There is currently no timeout concept for these listeners. One option is to manage the timeout yourself.
Here's how to do it when I also want to display a progress dialog when loading content.
private void showProgressDialog(boolean show, long time) { try { if (progressDialog != null) { if (show) { progressDialog.setMessage("Cargando..."); progressDialog.show(); new Handler().postDelayed(new Runnable() { public void run() { if(progressDialog!=null && progressDialog.isShowing()) { progressDialog.dismiss(); Toast.makeText(ActPreguntas.this, "Couldn't connect, please try again later.", Toast.LENGTH_LONG).show(); } } }, time); } else { progressDialog.dismiss(); } } }catch(IllegalArgumentException e){ }catch(Exception e){ } }
Therefore, when you make a request in Firebase, you call showProgressDialog (true, 5000) and after 5 seconds if the dialog remains there because it cannot connect, and then you do what you have, according to the timeout.
In the Firebase listener callback, you do this showProgressDialog (false, 0)
Hope this helps.
source share