Reputation: 853
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?
Upvotes: 0
Views: 260
Reputation: 58974
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.
AsyncTask()
or new Handler()
).runOnUiThread();
to set your data in List
or to set view components.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.
Upvotes: 1