Titanium Mobile Performance in add-removal views

In Titanium Mobile development, there is a performance penalty when trying detach or attach View object to a Windows object in the circumstances the View object containing many child objects.

Trying to implement master detail view I have a function called showItemPage() which will create a View object, and a bunch of button and label plus event listener, and attach to this View, where this view will attach into a master Window object. If there is previous other View added into Windows object, the previous view must be detached and removed before the new View can add into Windows object. The performance penalty arisen when I create the view object, and add a lot of objects inside, and then at the last attach the View into Windows object. The solution of this problem is tricky, just move “attach View into Windows object” code into the front just after you create the View, before you adding any children object into the View.

I wonder when adding the View object into a Window object, it become very slow when View object contains many child objects, but it is very fast when initially no any child objects added inside.

Side Note: to implement this I will create an object to hold the current active item view in outer context, then check every times, if the current active item view is exist, then remove that view from the Windows object, before adding the new view created to the Window object, and then set this view to current active item view.

Sample code:

if(activeItemView != null) {
	activeItemView = null;
activeItemView = itemView;

Author: fyhao

Jebsen & Jessen Comms Singapore INTI University College Bsc (Hon) of Computer Science, Coventry University

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.