Take the 2-minute tour ×

I have a large activity that contains 100 or more buttons. But it's working fine once loaded. Problem however is loading. From clicking its launch icon to getting the first view it takes 10-12 seconds. Until the first view, it shows gray title bar in black background.

At least, I want to show a simple progress bar or dialog while its loading. But it seems like you cannot show anything before setContentView executed. I think I have tried everything I could without any success. If you can give me any hint or idea, I would be thankful.


I found a dramatic resolution. It takes now a second to load the view. I didn't use splash, thread or async task at all - BTW, don't try to use thread or async on UI because Android UI is not thread-safe. Problem was that those buttons were based on a custom class that requires initialization to load same resource. - so 100 or more file operations were happening on setContentView. Making them a just single loading solved my problem.

share|improve this question
Are you tried ProgressDialog? –  Kiran Babu Nov 18 '11 at 9:17
@Kiran: Yes, I did. Any dialog does not show until main view is loaded. –  Paul Nov 18 '11 at 9:19
Do you Dynamically load your Button or you have 100 buttons defined in XML? –  Adil Soomro Nov 18 '11 at 9:20
@Adi, obviously loading them from xml. –  Paul Nov 18 '11 at 9:25
@Paul: could you load them in Java.? –  Adil Soomro Nov 18 '11 at 9:31
show 3 more comments

2 Answers

You are loading data on same UI thread , so nothing will be desplayed during the time of loading . Use Async Task for loading in separate thread.

1)Show a progressBar in onPreExecute() 2)load data in doInBackground() . no UI related stuff here 3) Update changes on UI ,hide progressBar in onPostExecute()

share|improve this answer
I've already tried Async Task. But it does not apply for setContentView. –  Paul Nov 18 '11 at 9:23
please share code . –  Shailendra Singh Rajawat Nov 18 '11 at 9:26
add comment

Use this code before setContentView() called.May be it helps


share|improve this answer
add comment

Your Answer


