服用的setContentView很长一段时间(10-15秒)来执行 [英] setContentView taking long time (10-15 seconds) to execute

查看:144
本文介绍了服用的setContentView很长一段时间(10-15秒)来执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含100个以上的按钮的大型活动。但是,它的优良工作一旦加载。然而,问题是加载。从单击其启动图标来获得的第一个视图需要10-12秒。直到第一个视图,它显示在黑色背景的灰色标题栏。

I have a large activity that contains 100 or more buttons. But it's working fine once loaded. Problem however is loading. From clicking its launch icon to getting the first view it takes 10-12 seconds. Until the first view, it shows gray title bar in black background.

至少,我想展示一个简单的进度栏或对话框,而它的加载。但它似乎像的setContentView执行之前,你不能显示任何东西。我想我已经尝试了一切我可以没有任何成功。如果你能给我任何提示或想法,我就谢天谢地了。

At least, I want to show a simple progress bar or dialog while its loading. But it seems like you cannot show anything before setContentView executed. I think I have tried everything I could without any success. If you can give me any hint or idea, I would be thankful.

更新:

我发现了一个戏剧性的分辨率。现在只需要一秒钟加载视图。我没有用飞溅,线程或异步工作在所有 - 顺便说一句,不要尝试使用线程或异步的UI由于Android UI不是线程安全的。问题是,这些按钮是根据需要初始化加载相同的资源的自定义类。 - 让100个以上的文件操作都发生在的setContentView。使之成为一个只是单一的装载解决我的问题。

I found a dramatic resolution. It takes now a second to load the view. I didn't use splash, thread or async task at all - BTW, don't try to use thread or async on UI because Android UI is not thread-safe. Problem was that those buttons were based on a custom class that requires initialization to load same resource. - so 100 or more file operations were happening on setContentView. Making them a just single loading solved my problem.

推荐答案

您加载在相同的用户界面线程的数据,所以什么也不会在装载时desplayed。 使用异步任务的加载在单独的线程。

You are loading data on same UI thread , so nothing will be desplayed during the time of loading . Use Async Task for loading in separate thread.

1),显示于preExecute在 A进度() 2)在加载数据doInBackground()。在这里没有UI相关的东西 3)更新的用户界面的变化,隐藏进度在 onPostExecute()

1)Show a progressBar in onPreExecute() 2)load data in doInBackground() . no UI related stuff here 3) Update changes on UI ,hide progressBar in onPostExecute()

这篇关于服用的setContentView很长一段时间(10-15秒)来执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆