Beginning Android PHẦN 9

có nghĩa là nhiều nhất là một thể hiện của hoạt động này sẽ được mở tại bất kỳ thời điểm nào vì vậy chúng tôi không gió lên với một bó toàn bộ các hoạt động tìm kiếm ít cluttering ngăn xếp hoạt động . 4. Các hoạt động LoremSearch được một yếu tố siêu dữ liệu, | 282 CHAPTER 31 INVOKING A SERVICE Here are the implementations of onResume and onPause for WeatherPlus Override public void onResume registerReceiver receiver new IntentFilter Override public void onPause unregisterReceiver receiver In onResume we register a static BroadcastReceiver to receive Intents matching the action declared by the service. In onPause we disable that BroadcastReceiver since we will not be receiving any such Intents while paused anyway. The BroadcastReceiver in turn simply arranges to update the forecast on the UI thread private BroadcastReceiver receiver new BroadcastReceiver public void onReceive Context context Intent intent runOnUiThread new Runnable public void run updateForecast And updateForecast uses the interface stub to call into the service and retrieve the latest forecast page also handling the case where the forecast is not yet ready null private void updateForecast try String page if page null new Runnable public void run updateForecast 4000 Toast .makeText this No forecast available 2500 .show CHAPTER 31 INVOKING A SERVICE 283 else null page text html UTF-8 null catch final Throwable t null runOnUiThread new Runnable public void run goBlooey t

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
145    435    5    30-06-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.