Tell me, please, how to make the ListView filled with updated data when you first open it. Now we have to go to another fragment and return to the right one. Using myClass.myFunction (), data is pulled from Firebase, compared with stored data in SQLite, and updated if necessary. The update takes place at the first opening of the fragment and this is evident in the logs, but the ListView displays outdated data.

public class Root_Exercises_Fragment_v2 extends BaseFragment { public static final String TAG = "TAG1"; private ListView mListview; private MyAdapter mAdapter; private DBHelper dbHelper; private SQLiteDatabase database; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.myLayout, container, false); new AsyncClass().execute(); mListview = (ListView) view.findViewById(R.id.mListview); return view; } class AsyncClass extends AsyncTask<Void, Void, Void> { @Override protected Void doInBackground(Void... parameter) { MyClass myClass = new MyClass(getActivity()); myClass.myFunction(); return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); Log.v("TAG", "In postExecute"); dbHelper = new DBHelper(getActivity()); database = dbHelper.getReadableDatabase(); mAdapter = new MyAdapter(getActivity(), database.rawQuery(getString(R.string.myQuery), null)) { }; mListview.setAdapter(mAdapter); } } } 
  • "The update takes place at the first opening of the fragment and this is evident in the logs, but outdated data is displayed in the ListView." - update of what? Database? those. Is there a database update, but does ListView show old data? - Iman
  • @Iman <yes, database update (new objects are downloaded and added + new ones are updated). Yes, ListView shows old data. - Dmitriy
  • Probably AsyncTask immediately goes to the onPostExecute method, without waiting for completion, try to wrap everything in try and set finnaly and set there return null; - Iman
  • @Iman, alas, did not help, but it turned out to find out that the data does not pull up only if the local database is empty. If there is at least one record in the database, then all subsequent records are displayed in the ListView without the need to re-enter the fragment. - Dmitriy
  • If the local database is empty, then where is the ListView then filled with old data? - Iman

0