E
E
Evgeny Nizamiev2015-09-30 18:44:19
Java
Evgeny Nizamiev, 2015-09-30 18:44:19

Why does the application lag after creating multiple fragments?

For the sake of interest, I decided to make something similar to browser tabs, but I ran into a problem that if you open (create fragments) about 10 tabs, then the application starts to shamelessly lag. If you switch between tabs, for example in the opposite direction, then the lags gradually disappear and in the tab where the lags were terrible, everything is already perfectly smooth. Here is a video for demonstration: https://drive.google.com/file/d/0B9So8zWjVX23MEFfa...
The video shows that fps sags terribly (from 120 to 30-40)
Project sources: https://github.com /RadiationX/ForPda (if possible, do not "throw tomatoes" for *sheepcode, this is essentially my first application written from scratch)
It is interesting to know the reason for this strange behavior. I thought that this was due to the fact that when changing fragments, onPause () does not work, but it seems to have nothing to do with it. I would be grateful if you could help me somehow with this problem.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
O
Oleg Gamega, 2015-09-30
@gadfi

webview is one of the slowest android elements ─ its work + while data is being loaded ...

D
Dmitry Bolshakov, 2015-10-01
@enq3

Evgeny Nizamiev : Of course, it will slow down when adding so many fragments to one activity.
Large lists with repeating elements are best done through adapters.
In this case, it is better to take ViewPager and FragmentPagerAdapter (FragmentStatePagerAdapter).

A
Alexey Perelygin, 2015-10-01
@orcDamnar

Using WebView is fraught with such consequences. If I were you, I would use a certain WebView pool, so that the meaning is as follows:
1. a pool is created somewhere in the heir of Application, and ideally, the pool should implement the singleinstance pattern
2. when creating a WebView fragment, we get from it (a pool, moreover , if there are free ones, then we give away the free one, if there is no free one, then a new one is created, with the settings you need)
3. when the fragment is destroyed, we clear the webview data and send the used webview back to the pull.
Such things will allow you to save memory. In general, in Java it is always better to use pools if you need to create a lot of some heavy objects of the same type, and standard tools do not provide for this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question