'this.isVisible() returns false after migration from targetSDKVersion from 30 to 31 in Android

In our Android project, we changed our targetSDKVersion from 30 to 31.

In our project, we have written following lines in TestViewPager.java class

if (ViewClass.this.isVisible()) {
    notifyDataSetChanged();
}

if (ViewClass.this.isVisible()) { // This condition return true when targetSDKVersion is 30.

After migration of targetSDKVersion from 30 to 31, This condition return false.

What may be the reason ?

Why isVisible() return false after migration ?

Will fragment behaviour gets differ for "31" targetSDKVersion ?

Please suggest solution.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source