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 .