I can not understand where the error, please suggest:

private class GetUserObject extends AsyncTask<Void, Void, Map<String, Object>> { @Override protected Map<String, Object> doInBackground(Void... params) { dataService.getFirebaseUsers().child(userPreferences.getUID()).addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { Post = (Map<String, Object>) snapshot.getValue(); Log.e("userBG ", "background"); } @Override public void onCancelled(FirebaseError firebaseError) { } }); return Post; } protected void onProgressUpdate(Void... progress) { Log.e("userProgress ", "progress"); } protected void onPostExecute(Map<String, Object> somemap){ super.onPostExecute(Post); //UserData userData = new UserData(Post); Log.e("userPE ", "after loading"); } } 

The point is that I get the execution of onPostExecute () until the completion of the execution of doInBackground. In the log:

 04-22 08:24:09.343 E/userPE: after loading 04-22 08:24:09.473 E/userBG: background 
  • show how you use your Asynctask . - Vladyslav Matviienko

2 answers 2

You have fun listeners in dataService.getFirebaseUsers().child..... I do not know what kind of lib it is. Perhaps by the description of the method, this is a database framework, but nevertheless, you use an anonymous class, which functions asynchronously, which means you can safely run it without async. doInBackground fair.

  dataService.getFirebaseUsers().child(userPreferences.getUID()).addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { Post = (Map<String, Object>) snapshot.getValue(); UserData userData = new UserData(Post) } @Override public void onCancelled(FirebaseError firebaseError) { } }); 

    From official documentation:

    Firebase data is retrieved by attaching an asynchronous listener to a Firebase reference.

    Ie your addListenerForSingleValueEvent asynchronous. Accordingly, the execution of your AsyncTask completed, and the listener completely different story.