The app has two fragments in the same activity. Fragment A have a button then press the button will start a parallel task, that will insert or update a lot of records in the database. Fragment B included a ViewPager
, the ViewPager
is using FragmentStatePagerAdapter
and held Fragment C, and each page will query and display a record from the database.
Fragment B will work properly, until press the button in Fragment A. After that, random pages in ViewPager will not work properly. Some pages will query a null record when the record exists. And there have two situations.
The first situation, Fragment A will have insert and update operations. That is the worst case, some specify records will get a null result in Fragment C, even though slide the ViewPager
to reopen the specified page, the record is still null until the parallel task in Fragment A is completed and reopen the Fragment B, then Fragment C can work properly again.
The second situation, Fragment A will have insert and query operations, without update operation. This case will not get a null result, but some specify records will get stuck until the parallel task in Fragment A is completed.
What causes these problems? Thank you in advance.