Hi am presently saving some values in firebase and i want my asynctask or method to wait until firebase as given me the data before it can move forward. with asynctask sometimes it works and sometimes it doesn't. i get null those times when it doesn't i guess maybe due to network strenght
    public static void connectWithHttpGetAudio(String email, String body) {
    class HttpGetAsyncTask extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... params) {
            final String paramEmail = params[0];
            final String paramBody = params[1];
            Firebase ref = new Firebase(Config.FIREBASE_URL);
            ref.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot snapshot) {
                    for (DataSnapshot postSnapshot: snapshot.getChildren()) {
                        //Getting the data from snapshot
                        Data data = snapshot.child(Config.MER).getValue(Data.class);
                        //Adding it to a string
                        String mail = data.getEmail();
                        String password = data.getPassword();
                        Mail m = new Mail(mail, password);
                        String[] toArr = {paramEmail};
                        m.setTo(toArr);
                        m.setFrom("support@gatesshield.com");
                        m.setSubject("G.A.T.E.S Emergency File");
                        m.setBody(paramBody);
                        try {
                            m.addAttachment(Environment.getExternalStorageDirectory().getAbsolutePath() + "/future.3gpp");
                            if (m.send()) {
                            } else {
                            }
                        } catch (Exception e) {
                            //Toast.makeText(MailApp.this, "There was a problem sending the email.", Toast.LENGTH_LONG).show();
                            //Log.e("GATES", "Could not send email.", e);
                        }
                    }
                }
                @Override
                public void onCancelled(FirebaseError firebaseError) {
                    System.out.println("The read failed: " + firebaseError.getMessage());
                }
            });
            return paramEmail;
        }
        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            }
        }
    }
    HttpGetAsyncTask httpGetAsyncTask = new HttpGetAsyncTask();
    // Parameter we pass in the execute() method is relate to the first generic type of the AsyncTask
    // We are passing the connectWithHttpGet() method arguments to that
    httpGetAsyncTask.execute(email, body);
}
 
    