TAILIEUCHUNG - Lập trình Androi part 22

Tốt nhất, bạn muốn các hoạt động của bạn sẽ được cương mạnh me, vì vậy người dùng của bạn không cảm thấy rằng ứng dụng của bạn là chậm chạp. Đáp ứng với đầu vào sử dụng một cách nhanh chóng (ví dụ, trong thời hạn trong 200 mili giây) là một mục tiêu tốt. Ở mức tối thiểu, tuy nhiên, bạn cần chắc chắn rằng bạn trả lời trong vòng 5 giây, vì sợ rằng các quyết định ActivityManager đóng vai trò của Grim Reaper và giết tắt hoạt động của bạn như đang được nonresponsive | Chapter Dealing with Threads Ideally you want your activities to be downright snappy so your users don t feel that your application is sluggish. Responding to user input quickly . within in 200 milliseconds is a fine goal. At minimum though you need to make sure you respond within 5 seconds lest the ActivityManager decide to play the role of the Grim Reaper and kill off your activity as being nonresponsive. Of course your activity might have real work to do which takes nonnegligible amount of time. This invariably involves the use of a background thread. Android provides a veritable cornucopia of means to set up background threads yet allow them to safely interact with the UI on the UI thread. The safely interact concept is crucial. You cannot modify any part of the UI from a background thread. That must be done on the UI thread. This generally means that there will need to be some coordination between background threads doing the work and the UI thread showing the results of that work. This chapter covers how to work with background and UI threads in your Android applications. Getting Through the Handlers The most flexible means of making an Android-friendly background thread is to create an instance of a Handler subclass. You need only one Handler object per activity and you do not need to manually register it. Merely creating the instance is sufficient to register it with the Android threading subsystem. Your background thread can communicate with the Handler which will do all of its work on the activity s UI thread. This is important as UI changes such as updating widgets should occur only on the activity s UI thread. You have two options for communicating with the Handler messages and Runnable objects. 155 Messages To send a Message to a Handler first invoke obtainMessage to get the Message object out of the pool. There are a few flavors of obtainMessage allowing you to create empty Message objects or ones populated with message identifiers and arguments. .

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.