user1027742
user1027742

Reputation: 21

View being rendered extremely slowly on emulator and device

I have a series of complex views being displayed on the screen and I also require to switch between views dynamically at runtime which I do so by removing views and adding new views(sometime just setting visiblility).

Now the problem is that the views take an extremely large amount of time to be rendered(in excess of 7-8 seconds).

I have put time stamps within my methods and all of them seem to return pretty quick. But even after the last of my methods return, the view is not rendered and i have to wait to see it actually displayed. The UI is pretty unresponsive after that and I get ANR pretty frequently.

Can anybody point out why is it so sluggish?

I am loading a lot of images from the file system at run time using Drawable.createFromPath(). Could this be the problem?

Upvotes: 1

Views: 133

Answers (2)

user1027742
user1027742

Reputation: 21

I have found out a solution for the same and am posting it for anyone facing similar issues. The problem was due to deep nesting of views. Since the layout was fairly complex, the views were nested fairly deep. And after a certain level 14- 15, performance starts degrading pretty drastically. On merging some of the stub layouts (place holders etc.) the performace was improved drastically. The hierarchy viewer was very useful in debugging this issue. Some more observations were: 1. Relative layouts when nested are pretty slow whilst LinearLayouts are not so much. 2. The soft keyboard is sluggish when used within dialogs or when triggered form a deeply nested Relative layout(Hierarchy consists of relative layouts primarily.)

Upvotes: 1

Arun George
Arun George

Reputation: 18592

One of the reason why an application becomes sluggish is when you do some time consuming Non-UI activity in a UI Thread. I would suggest that you carefully look into your code and determine which all activity takes time and you may use AsyncTask to perform these activities.

Refer to this link for more info: http://developer.android.com/reference/android/os/AsyncTask.html

Upvotes: 0

Related Questions