开发者

How to open an activity instantly and then loading its layout

Here's the deal: I have a heavy layout that cannot be improved any further, as it contains LinearLayouts with weights (so I cannot use RelativeLayouts). In Activity A, I click on a list item that fires off Activity B. Activity A freezes until Activity B is fully loaded, then Activity B gets shown. So this is the complete queue of events:

  1. Activity A: open B
  2. Activity A: freezes
  3. Activity B: finishes inflation/setContentView
  4. Activity A: goes back into the application stack
  5. Activity B: gets shown

How can I immediately show Activity B so that Activity A won't freeze? I thought about inflating a temporary layout in B, but I need a callback method that tells me that B is fully visible and I can then replace the temporary layout with the real one.

C开发者_Go百科an anyone help me? Thank you!

Off topic: layout inflation in Android is a real pain, it shouldn't block the whole UI, but it does. Same thing for setting list adapters.


You should do your time taking task of Activity B in thread and if you need to update the UI after your task completes then do it using handler.


You can do your time consuming loading using AsyncTask .You can use

 doInBackgroundMethod to load the data
 onProgressUpdate you can bind your layout to data.

If you works this way your Activity will not be frozen

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜