一个应用程序中存在 2 个屏幕,在第一个屏幕中只有一个按钮,在第 2 个屏幕中,在单个列表中列出 1000 个项目,如果用户单击第一个屏幕中的按钮,他将定向到第 2 个屏幕,但在第 2 个屏幕 1000列表项用于加载这 1000 个列表项需要很长时间,因此用户单击菜单按钮并转到其他应用程序,一段时间后用户返回主应用程序然后列表视图处于先前状态,即仍在加载,我想通过在后台使用服务实现来解决这个问题,在android中可以吗?
问问题
75 次
1 回答
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**
于 2012-10-19T15:39:22.783 回答