开发者

Start all tab's activities for pre-cache

开发者 https://www.devze.com 2022-12-24 03:54 出处:网络
I have a TabActivity with three tabs defined. The first tab is light-weight and renders in acceptable time. But the 2nd and 3rd tab, does need a couple of seconds to get visually r开发者_开发知识库end

I have a TabActivity with three tabs defined. The first tab is light-weight and renders in acceptable time. But the 2nd and 3rd tab, does need a couple of seconds to get visually r开发者_开发知识库endered, after I click them. I would like to launch them, after I've loaded my first tab, in background for pre-cache. Once they are loaded, I can switch quickly between them.

So I am wondering how can I launch the 2nd and 3rd tab. They are new activities loaded in the view area.


Step #1: Get rid of all the activities being used as the contents of tabs.

Step #2: Rewrite them as being Views (children of your FrameLayout in your main layout file for the TabHost activity), and get it working. Having activities as the contents of tabs adds overhead for no meaningful benefit.

If that is insufficient of a performance gain, then...

Step #3: Move your second and third tabs into separate layout files. Inflate them in onCreate() but just hold onto them (don't attach them to the TabHost). When adding the tab specs, use the one that takes a TabContentFactory, and have the factory grab the pre-built Views.

If that simply shifts your performance problem into onCreate(), then...

Step #4: Try inflating and setting up those views in background threads. This may just blow up, because Android does not like UI operations on background threads. Even if it does work, you will need to have smarts to deal with the possibility that the user clicks on the 2nd tab before you are done with your work.

Or, you could just speed up whatever those tabs are trying to do so they don't take as much time, at least at the outset.

0

精彩评论

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