I've encountered a memory leak with SwipeRefreshLayout and wondering if there's any way to maybe solve this with a workaround?
In a empty project, with a swipe layout as the root of the main activity, if you swipe down, and minimize the app while it's refreshing, even if you put a stop in onStop or onPause, it will continue to eat CPU/Battery as long as the app is open in the background.
The cpu profiler I attached will just repeatedly do what's in that image forever, and the energy profiler shows an always or almost always constant usage while backgrounded.
Any ideas on what I can do to stop this?
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
override fun onStop() { //tried in onPause as well
swipeRefresh.isRefreshing = false
swipeRefresh.clearAnimation() //I tried with/without this
super.onStop()
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipeRefresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
In onPause
swipeRefresh.isEnabled = false
OnResume
swipeRefresh.isEnabled = true
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With