Home » Android » android – SwipeRefreshLayout refresh conflict with fragmentTransactions

android – SwipeRefreshLayout refresh conflict with fragmentTransactions

Posted by: admin June 16, 2020 Leave a comment

Questions:

TLDR: here’s my bug report : http://goo.gl/UgBFW2

Using a SwipeRefreshLayout if I press back and trigger either a getSupportFragmentManager().popBackstack(), super.onBackPressed() or fragmentTransaction.replace() right when the adapter triggers the views refresh, the two fragments overlap (a video showing the problem can be found in the top link).

I tried several things and adding a background is not a solution since the list fragment is in the foreground and the one clickable is the previous fragment.

Has anyone found a solution to this ?

Replacing Fragment does not work properly while swipeRefresh is running

How to&Answers:

Add this to the fragment that contains the swipe

@Override
public void onPause() {
    super.onPause();
    if (swipeRefreshLayout!=null) {
        swipeRefreshLayout.setRefreshing(false);
        swipeRefreshLayout.destroyDrawingCache();
        swipeRefreshLayout.clearAnimation();
    }
}

Answer:

Its a bug. Google may fix it in future.

Android Issue 78062

Answer:

Try wrapping the SwipeToRefreshLayout inside a FrameLayout. It fixed the issue for me.

Answer:

Issue I Have Faced

I was facing the same issue in appcompat-v7:25.1.0.
I have tried all this below codes still the problem persist

@Override
public void onPause() {
    super.onPause();
    if (swipeRefreshLayout!=null) {
        swipeRefreshLayout.setRefreshing(false);
        swipeRefreshLayout.destroyDrawingCache();
        swipeRefreshLayout.clearAnimation();
    }
}

Solution

If any one facing the same issue Please downgrade appcompat to 25.0.1 and use the above snippet to stop animating the same. It is working fine for me