views:

106

answers:

1

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.

+1  A: 

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.

CommonsWare
I did step 1 and step 2. I don't see step 3 necessary as not my views are slow, my adapters compute time are slow. Still takes 5-7 seconds when testing at run time(no debug). If my adapters are empty, load time is instant.
Pentium10
Then create your adapters in a background thread *but do not attach them to the `ListView` until they are ready*. An adapter does not actually create `Views` until they are connected to a `ListView` (or other `AdapterView`), so they are safe for use in the background. You will still need to deal with the case where the the user tabs over to a tab whose adapter is not yet ready (e.g., pop a `ProgressDialog`).
CommonsWare
I did the threading stuff it works well, and now I am doing the progress dialog, and will use together with the empty text for ListViews.
Pentium10