Why notifyDataSetChanged not working on some devices?


I’ve got a viewpager with 5 fragments.

My problem is, that calling


doesn’t work properly on some devices.

For example, on my BQ Aquaris mobile phone it works fine. It refreshes all the five fragments.

But on my Huawei Honor mobile phone it just refresh the first fragment, and the others are left like they are.

How can I avoid this problem?

BQ Aquaris android version is: 7.1.1

Huawei Honor android version is: 7.0

You can try to set viewPager.setOffscreenPageLimit to 5 (see https://developer.android.com/reference/android/support/v4/view/ViewPager.html#setOffscreenPageLimit(int) for more information).

But it is not recommended to hold a lot of pages in memory. An alternative is to use the viewPager.addOnPageChangeListener and update the corresponding fragment.