App slows down when more than 20 fragments are added to backstack

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



App slows down when more than 20 fragments are added to backstack



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?




1 Answer
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.


UI


Main thread


AsyncTask()


new Handler()


runOnUiThread();


List



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.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS