1

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.

UPDATE:

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.

Tae-Sung Shin
  • 20,215
  • 33
  • 138
  • 240

2 Answers2

1

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()

Shailendra Singh Rajawat
  • 8,172
  • 3
  • 35
  • 40
0

Use this code before setContentView() is called. Maybe it helps.

requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
requestWindowFeature(Window.FEATURE_PROGRESS);

setProgressBarIndeterminateVisibility(true);
setProgressBarVisibility(true);
tvkanters
  • 3,519
  • 4
  • 29
  • 45
Kiran Babu
  • 1,893
  • 2
  • 13
  • 7