Farzad Khalafi
Farzad Khalafi

Reputation: 309

Speed up dynamic view creation for android

I have created an android app that works as designed. However, onCreate() uses dynamic(not xml) to create 80% of my layout,which are consist of buttons. It takes about 3-4 second to build the entire layout, which is too slow. Is there any suggestions to speed up this process?

Things I tried: 1. using fewer view objects, it has not improved the speed and using listview and linearview had very minimal gains 2. I tried moving some of my to onResume(), no gain 3. using serializer to keep my view in sharedpreferences did not work

Are there any ways to speed up dynamic view creation?

Upvotes: 2

Views: 1722

Answers (2)

Bruno Nardini
Bruno Nardini

Reputation: 461

Try to put all code from layout inside a runOnUiThread() method from Activity. You can use this in onCrete() or onResume() (onResume is called always when Activity came to front). Try like this:

runOnUiThread(new Runnable() {          
        @Override
        public void run() {
            // Do stuff from layout
        }
    });

This way, the code will running in a thread and it will free the Activity to show itself.

Upvotes: 2

chris-tulip
chris-tulip

Reputation: 1830

have you thought about using a List View and inflating a custom view from xml into the convert views which are recycled?

I don't know if this would work in your case since I don't know what your code does but this seems like the proper place ot use an adapter and some sort of List element

Upvotes: 1

Related Questions