如果活动需要很长的时间来加载,它要求部队密切,如何解决呢? [英] If an Activity takes long time to Load, it asks for force close, how to solve this?
问题描述
几乎所有我的应用程序的活动需要与Web服务器交互获取数据,然后加载活动画面。因此,在如果互联网是缓慢的任何时刻,它需要大量的时间和经过一些12-15秒它说:无法加载,ForceClose /等待。如何应用避免这种情况?什么是他们跟随,当第一次3-4活动正常工作(当净是好的)解决方案则有些活动需要很长的(因为糟糕的互联网/网络,如果没有了)
Almost all the activities in my application need to interact with a web server to get data and then load the Activity screens. So at any moment if the internet is slow, it takes a lot of time and after some 12-15 secs it says "unable to load, ForceClose/Wait". How does applications avoid this? What is the solution they follow, when 1st 3-4 activities work fine (when net is good) then some Activity takes long(because of bad internet/ if internet is gone)
推荐答案
通过优化code,其次做一个单独的线程(如AsynTask)您的网络/互联网的工作。
By Optimizing your code, Secondly do your Network/Internet work on a separate thread(like AsynTask).
链接:<一个href=\"http://developer.android.com/reference/android/os/AsyncTask.html\">http://developer.android.com/reference/android/os/AsyncTask.html
这不会阻止你的用户界面。
This will not block your UI.
希望这有助于
这篇关于如果活动需要很长的时间来加载,它要求部队密切,如何解决呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!