开始为pre-缓存中的所有选项卡的活动缓存、选项卡、pre

2023-09-05 10:39:28 作者:ぁ真de¥╄→愛你

我有一个 TabActivity 与定义的三个选项卡。第一个标签是重量轻,使得在可接受的时间。但第二和第三个标签,的确需要几秒钟就可以直观地呈现在我点击它们。我想发动他们,我装我的第一个选项卡,在后台为pre-高速缓存。一旦被加载,我可以在它们之间迅速切换。

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:摆脱所有被用作选项卡的内容的活动

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

步骤#2:重写它们作为浏览(在为您的主要布局文件中的的FrameLayout 儿童 TabHost 的活动),并得到它的工作。有活动标签页的内容,增加了开销毫无意义的好处。

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

第三步:将你的第二个和第三个选项卡到单独的布局文件。充气它们的onCreate()只是不放他们(不要将它们连接到 TabHost )。当添加标签规范,使用一个需要 TabContentFactory ,并有工厂抢pre建浏览

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.

如果说只是把你的性能问题,到的onCreate(),然后...

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

步骤#4:尝试充气和设置在后台线程这些看法。这可能只是炸毁,因为Android不喜欢在后台线程的UI操作。即使不工作,你将需要智慧来处理,用户点击第二个选项卡上的可能性之前,你与你的工作完成。

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.