In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "what is the use of Service in Android". The editor shows you the operation process through an actual case. The method of operation is simple and fast, and it is practical. I hope this article "what is the use of Service in Android" can help you solve the problem.
1 Service essential structure
Let's start with the analysis of the fundamental meaning of Service. The essence of a service is to respond to client requests. To provide services, it is necessary to establish a framework for receiving requests, processing requests, and responding to customers. I think Android Service designers will always keep the essential block diagram of this service in mind. From a programmatic point of view, the service must have a closed loop framework and a request processing framework.
To analyze the service frame clearly, it is necessary to understand the following mechanisms and their composition.
(1) where is the closed loop structure placed?
(2) how are requests distributed and managed?
(3) how is the processing framework established?
(4) how is the conceptual framework established?
2 Analysis of the basic framework of Service
In the design of Android, Native Service and Android Service adopt the same closed loop framework. The closed loop frame is placed in the C++ space on Native.
In the service framework, ProcessState is the common part, and the main framework of this common part is the closed loop framework and the processing framework after receiving the request from Binder. We represent the service framework in ProcessSate, in short:
(1) addservice
(2) the framework of closed cycle processing is established.
Java Code:
Int main (int argc, char** argv) {sp proc (ProcessState::self ()); addService (String16 ("xxx0"), new xxx0Service ()); addService (String16 ("xxx1"), new xxx1Service ()); ProcessState::self ()-> startThreadPool (); IPCThreadState::self ()-> joinThreadPool (); / / closed loop frame}
2.1 Native Service
Native Service is a service established through Init.rc scripts during the Init phase of the system.
Java Code:
Int main (int argc, char** argv) {sp proc (ProcessState::self ()); sp sm = defaultServiceManager (); LOGI ("ServiceManager:% p", sm.get ()); AudioFlinger::instantiate (); MediaPlayerService::instantiate (); CameraService::instantiate (); AudioPolicyService::instantiate (); ProcessState::self ()-> startThreadPool (); IPCThreadState::self ()-> joinThreadPool ();}
(1) the service process establishes the ProcessState object and registers the object in the context of the process.
(2) create a new AudioFlinger object and register the object in Service Manager Service.
(3) receive the request at the beginning, process the request, and reply to this circular closed framework.
2.2 Android Service
Androids service is a service established during the initialization of the system Phase II (Init2).
You don't see the loop structure in SystemServer.java, but you can see that you have set up the implementation functions of init2, set up a lot of services, and AddService to service Manager.
Init1 () is implemented in the Native space (com_andoird_server_systemServer.cpp). As soon as we look at this function, we can see that the closed loop processing framework is here:
Init1- > system_init () @ System_init.cpp
We saw this long-lost loop closure management framework in system_init ().
Java Code:
{Call "com/android/server/SystemServer", "init2" ProcessState::self ()-> startThreadPool (); IPCThreadState::self ()-> joinThreadPool ();} that's all for "what's the use of Service in Android". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.