TAILIEUCHUNG - Lập trình Androi part 23

Có bốn phương pháp bạn có thể ghi đè lên trong AsyncTask để hoàn thành kết thúc của bạn. Một trong những bạn phải ghi đè lên, cho tầng lớp công việc để có ích, là doInBackground (). Điều này sẽ được gọi bằng một sợi AsyncTask trên nền. Nó có thể chạy miễn là cần thiết để hoàn thành bất cứ công việc cần phải làm cho nhiệm vụ này cụ thể. Lưu ý, mặc dù, rằng nhiệm vụ có nghĩa là để được hữu hạn; sử dụng AsyncTask cho một vòng lặp vô hạn không được khuyến cáo. | CHAPTER 15 Dealing with Threads Override one or more AsyncTask methods to accomplish the background work plus whatever work associated with the task that needs to be done on the UI thread . update progress . When needed create an instance of the AsyncTask subclass and call execute to have it begin doing its work. What you do not need to do is Create your own background thread. Terminate that background thread at an appropriate time. Call all sorts of methods to arrange for bits of processing to be done on the UI thread. AsyncTask Generics and Varargs Creating a subclass of AsyncTask is not quite as easy as say implementing the Runnable interface. AsyncTask uses generics and so you need to specify three data types The type of information that is needed to process the task . URLs to download The type of information that is passed within the task to indicate progress The type of information that is passed when the task is completed to the post-task code What makes this all the more confusing is that the first two data types are actually used as varargs meaning that an array of these types is used within your AsyncTask subclass. This should become clearer as we work our way toward an example. The Stages of AsyncTask There are four methods you can override in AsyncTask to accomplish your ends. The one you must override for the task class to be useful is doInBackground . This will be called by AsyncTask on a background thread. It can run as long as necessary in order to accomplish whatever work needs to be done for this specific task. Note though that tasks are meant to be finite using AsyncTask for an infinite loop is not recommended. The doInBackground method will receive as parameters a varargs array of the first of the three data types listed in the preceding section the data needed to process the task. So if your task s mission is to download a collection of URLs doInBackground will receive those URLs to process. The doInBackground method must return a value

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.