Henrique Rocha
Henrique Rocha

Reputation: 1737

Android ProgressBar skipping frames

I'm loading twenty items (WebViews) into a LinearLayout and while they are loading I'm showing a ProgressBar that hides that LinearLayout to provide feedback to the user that I'm doing work.

The problem is that the progress wheel freezes and I get warning in LogCat from Choreographer saying "Skipped frames! The application may be doing too much work on its main thread."

To avoid this problem I actually tried to change from using a LinearLayout with all 20 items and using a ListView with an Adapter. I ran into WebView recycling problems, so I eliminated the recycling and actually used an array of 20 items and every time the ListView needs to load an item, it loads from that array if it was already inflated before.

Then I got into the problem that I can't scroll to a specified item because the ListView only loads the WebViews when necessary so it can't calculate the amount of scrolling that needs to be done since the heights of the WebViews vary.

Conclusion, I had to get back to my LinearLayout implementation adding all the WebViews to it.

Is there a solution to this problem? If there isn't, I'm thinking about only showing a "Loading..." TextView instead of an animated ProgressBar.

By the way, before someone asks, I'm using a Nexus 4 to test the app and not the emulator and I'm not doing database accesses in the UI thread.

Thanks in advance.

Upvotes: 1

Views: 807

Answers (1)

Romain Guy
Romain Guy

Reputation: 98501

A WebView is a heavy and expensive object, every time you add a new WebView to the window, it has to be initialized, measured and laid out. This is what's causing you to skip frames. You could check by using traceview or systrace to see where you're spending time.

Upvotes: 1

Related Questions