I have a fragment that loads tabs dynamically into the view pager where data in each tab will be loaded on the result of an api call. Each fragment will have a minimum of 4 tabs. When this fragment is added into the backstack multiple times (normally more than 20), the app starts to lag and it becomes very slow to scroll through the list. Is there a way to solve this?
Asked
Active
Viewed 236 times
1 Answers
1
This issue is related to managing UI Thread & Worker Thread.
Perhaps you are doing so much work in UI Thread. Like filtering list or creating Map (It can be anything, as I cant see your code.) etc.
Solution:
You should do only UI work in UI
or Main thread
. Like if you are fetching & parsing response.
- Fetch api data in Worker Thread (
AsyncTask()
ornew Handler()
). - Parse data in worker thread, because parsing too much data will cause UI lagging.
- Filter lists or prepare data in same worker thread.
- Then use
runOnUiThread();
to set your data inList
or to set view components. - If you have long list in every fragment then use Pagination.
There can be many other improvements in your code. You should identify and resolve that.
Keypoint is use UI/Main thread for communicating to View. And use Worker Thread for background process.
If you properly manage threads in your app, your app will never hang.

Community
- 1
- 1

Khemraj Sharma
- 57,232
- 27
- 203
- 212
-
i have add some fragment after lagging application please check my question :- https://stackoverflow.com/questions/60880908/add-some-fragment-continuously-then-recyclerview-scroll-lagging any help very appreciated – Kishan Viramgama Apr 08 '20 at 05:41