TAILIEUCHUNG - Lập trình Androi part 42

Như đã nói trước đó, Android dịch vụ cho quá trình dài đang chạy mà có thể cần phải tiếp tục chạy ngay cả khi tách riêng từ hoạt động bất kỳ. Ví dụ như chơi nhạc ngay cả khi hoạt động máy nghe nhạc được thu thập rác, bỏ phiếu trên Internet RSS / Atom nguồn cấp dữ liệu cập nhật, và duy trì một chat trực tuyến kết nối ngay cả khi trò chuyện khách hàng mất tập trung do một cuộc gọi điện thoại đến | Chapter Creating a Service As noted previously Android services are for long-running processes that may need to keep running even when decoupled from any activity. Examples include playing music even if the player activity gets garbage-collected polling the Internet for RSS Atom feed updates and maintaining an online chat connection even if the chat client loses focus due to an incoming phone call. Services are created when manually started via an API call or when some activity tries connecting to the service via interprocess communication IPC . Services will live until no longer needed and if RAM needs to be reclaimed or until shut down on their own volition or because no one is using them anymore . Running for a long time isn t without its costs though so services need to be careful not to use too much CPU or keep radios active too much of the time lest the service cause the device s battery to get used up too quickly. This chapter covers how you can create your own services. The next chapter covers how you can use such services from your activities or other contexts. Both chapters will analyze the Service WeatherPlus sample application. This chapter focuses mostly on the WeatherPlusService implementation. WeatherPlusService extends the weatherfetching logic of the original Internet Weather sample by bundling it in a service that monitors changes in location so the weather is updated as the emulator is moved. Service with Class Creating a service implementation shares many characteristics with building an activity. You inherit from an Android-supplied base class override some life-cycle methods and hook the service into the system via the manifest. So the first step in creating a service is to extend the Service class in our case with our own WeatherPlusService subclass. Just as activities have onCreate onResume onPause and the like Service implementations have their own life-cycle methods such as the following 279 onCreate As with activities called when the .

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.