eclipse Phonegap-跳过33帧!应用程序可能在其主线程上做了太多工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20465088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Phonegap-Skipped 33 frames! The application may be doing too much work on its main thread
提问by user2750238
I'm new for the development of android-phonegap application. I want to display the students details from a database in the server. When i tried to connect with database, it shows me "Skipped 33 frames! The application may be doing too much work on its main thread" in eclipse IDE.
我是 android-phonegap 应用程序开发的新手。我想从服务器中的数据库中显示学生的详细信息。当我尝试连接数据库时,它在 Eclipse IDE 中显示“跳过 33 帧!应用程序可能在其主线程上做了太多工作”。
Please give me solution, or suggestion if any.
请给我解决方案或建议(如果有)。
回答by Techfist
This is because Choreographer of android is not getting required resource for performing proper display hence skipping frames.
这是因为 android 的 Choreographer 没有获得执行正确显示所需的资源,因此跳帧。
this mainly happens when user perform heavy operations in main thread, remember Android is single threaded system, there is Single main thread where all the other subsystem hooks upon to perform task such as Activities,Services,Content Providers. thats why when you perform network operation directly on main thered you get Application not responding message.
这主要发生在用户在主线程中执行繁重操作时,请记住 Android 是单线程系统,有一个主线程,所有其他子系统都挂在其中执行诸如活动、服务、内容提供者之类的任务。这就是为什么当您直接在 main red 上执行网络操作时,您会收到 Application not Responding 消息。
To elaborate upon your situation, do the following.
要详细说明您的情况,请执行以下操作。
If you have any network operation being done in main thread, move them to a separate thread, in Android native we have AsyncTask for that, try finding thread mechanism in Phonegap
If you have any heavy operations such as Compression of Bitmap etc, handle them efficiently by threads or post runnable logic, this will make sure your main thread is free for trivial task such as generation of display processing of events etc.
如果你在主线程中进行了任何网络操作,请将它们移动到一个单独的线程中,在 Android 原生中我们有 AsyncTask,尝试在 Phonegap 中找到线程机制
如果您有任何繁重的操作,例如 Bitmap 的压缩等,请通过线程或 post runnable 逻辑有效地处理它们,这将确保您的主线程可以自由执行琐碎的任务,例如生成事件的显示处理等。
In the sense, any logic which might take some time, move it to threads, this will make sure your display run smooth.
从某种意义上说,任何可能需要一些时间的逻辑,将其移至线程,这将确保您的显示运行顺畅。
Hope it help.
希望有帮助。
回答by Amit Gupta
Do your Database or server interaction like below
像下面这样进行数据库或服务器交互
this.cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
// Place your Database and Network related code here
//
}
});
Hope this help you.
希望这对你有帮助。