1 つのアプリケーションに 2 つの画面が存在します。最初の画面にはボタンが 1 つしかなく、2 番目の画面には単一のリストに 1000 個のリスト項目があります。ユーザーが 1 番目の画面でボタンをクリックすると、2 番目の画面に移動しますが、2 番目の画面では 1000 になります。これらの 1000 個のリスト アイテムをロードするためのリスト アイテムが存在します。長い時間がかかるため、ユーザーがメニュー ボタンをクリックして他のアプリケーションに移動すると、しばらくしてユーザーがメイン アプリケーションに戻ると、リスト ビューは以前の状態、つまりまだロード中です。バックグラウンドでサービス実装を使用してこれを解決するには、アンドロイドで可能ですか?
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 に答える