When switch fragment with SwipeRefreshLayout during refreshing, fragment freezes but actually still work
Well... After some struggling I eventually solved this problem by myself, in a tricky way...
I just need to add these in onPause()
:
@Override
public void onPause() {
super.onPause();
...
if (mSwipeRefreshLayout!=null) {
mSwipeRefreshLayout.setRefreshing(false);
mSwipeRefreshLayout.destroyDrawingCache();
mSwipeRefreshLayout.clearAnimation();
}
}
SwipeRefreshLayout Got Action_Move freezes view
Ok I found the solution. I post it because it can happen to everybody and that's a little boring (two days to find for me).
First I had this in my XML which contains the SwipeRefreshLayout (a fragment):
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/news_container_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:background="@color/news_background">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/news_list_recycle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:dividerHeight="5dp" />
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/news_progress"
android:visibility="invisible"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
So, to fix the bug, YOU NEED TO JUST HAVE THE RECYCLEVIEW (or listview) IN YOUR SWIPEREFRESHLAYOUT :
So, I Move my progressBar and make the RelativeLayout as the rootView.
Result :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/news_progress"
android:visibility="invisible"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/news_container_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:background="@color/news_background">
<android.support.v7.widget.RecyclerView
android:id="@+id/news_list_recycle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:dividerHeight="5dp" />
</android.support.v4.widget.SwipeRefreshLayout>
I hope it will help someone else later.
Android fragment twice when setRefreshing(false) on swipeRefreshLayout during fragment transaction
I found a similar question on SO:
When switch fragment with SwipeRefreshLayout during refreshing, fragment freezes but actually still work
I use appcompat-v7:23.3.0. This answer worked for me:
This issue seems to still be occurring in appcompat 22.1.1. Wrapping
the SwipeRefreshLayout inside a FrameLayout solved this for me.
So my subject fragment layout looks like this:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/refresher"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
SwipeRefreshLayout Freezes on API 4.2.2
I believe the problem was occurring due to changes for SwipeRefreshLayout
in v23 compared to v22, same for RecyclerView
. Everything works fine after switching to v23.0.1
compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.android.support:cardview-v7:23.0.1'
compile 'com.android.support:design:23.0.1'
compile 'com.android.support:palette-v7:23.0.1'
compile 'com.android.support:recyclerview-v7:23.0.1'
Strange behaviour replacing fragments in Android
Ok, I found out the problem.
It seems that a SwipeRefreshLayout was the one causing all the problems. One of my fragments was using it, and after switching fragments a couple of times it gets stuck.
Removing it, or disabling it setEnabled(false) solves all the problems.
I hope it will help to anyone that is having the same problem!
Another thread in SO that refers to the same problem: When switch fragment with SwipeRefreshLayout during refreshing, fragment freezes but actually still work
Bug : SwipeRefreshLayout view doesn't get removed from Fragment container
It's a bug in SwipeRefreshLayout
which is not fixed from long time despite having enough stars. You can keep track of issue here.
Related Topics
Gradle Sync Failed Could Not Find Constraint-Layout:1.0.0-Alpha2
Firebase Ontokenrefresh() Is Not Called
Android: Setselection Having No Effect on Spinner
How to Hide Toolbar When I Scrolling Content Up
What Is a Maximum Size of SQLite Database on Android
Listen to Own Application Uninstall Event on Android
How to Disable Status Bar Click and Pull Down in Android
Using Camera in the Android Emulator
Run Task Before Compilation Using Android Gradle Plugin
How to Open My Existing Eclipse Projects in Android Studio
Programmatically Add View One Below Other in Relative Layout
Seekbar and Media Player in Android
Adding Fling Gesture to an Image View - Android
How to Highlight the Selected Item of Recycler View