加载列表视图时如何实现后台服务?

时间:2012-10-17 17:49:28

标签: android-service

一个应用程序中有2个屏幕, 在第一个屏幕中只有一个按钮,在第二个屏幕1000中列出单个列表中的项目,如果用户点击第一个屏幕中的按钮,他将指向第二个屏幕,但在第二个屏幕1000中,列表项目用于加载这些1000列出项目需要很长时间,因此用户点击菜单按钮并转到其他应用程序,一段时间后用户返回主应用程序然后列表视图处于先前状态即仍在加载,我想通过使用服务实现解决此问题背景,它可能在Android?

1 个答案:

答案 0 :(得分:0)

**您可以使用线程,异步任务和服务运行后台进程 但对于UIupdating UIthread是最好的过程,因为

When your app performs intensive work in response to user interaction, this single thread model can yield poor performance unless you implement your application properly. Specifically, if everything is happening in the UI thread, performing long operations such as network access or database queries will block the whole UI. When the thread is blocked, no events can be dispatched, including drawing events. From the user's perspective, the application appears to hang. Even worse, if the UI thread is blocked for more than a few seconds (about 5 seconds currently) the user is presented with the infamous "application not responding" (ANR) dialog. The user might then decide to quit your application and uninstall it if they are unhappy.

Additionally, the Andoid UI toolkit is not thread-safe. So, you must not manipulate your UI from a worker thread—you must do all manipulation to your user interface from the UI thread. Thus, there are simply two rules to Android's single thread model:

Do not block the UI thread Do not access the Android UI toolkit from outside the UI thread**