Question

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 rendered, 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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top