Getsystemservice is an important API for Android, a method of activity that obtains the corresponding object based on the name passed in, and then translates it into the appropriate service object. The following describes the system's corresponding services.
| The name passed in |
The returned object |
Description |
| Window_service |
WindowManager |
To manage open Windows programs |
| Layout_inflater_service |
Layoutinflater |
Gets the view defined in the XML |
| Activity_service |
Activitymanager |
Managing the system state of an application |
|
Power_service |
Powermanger |
Service of power supply |
| Alarm_service |
Alarmmanager |
Services for the alarm clock |
|
Notification_service |
Notificationmanager |
Service for status bar |
| Keyguard_service |
Keyguardmanager |
Service for keyboard lock |
| Location_service |
Locationmanager |
Location of the service, such as GPS |
| Search_service |
Searchmanager |
Search for services |
| Vebrator_service |
Vebrator |
Mobile phone Shake Service |
| Connectivity_service |
Connectivity |
Network-connected Services |
| Wifi_service |
Wifimanager |
Wi-Fi Service |
| Telephony_service |
Teleponymanager |
Telephone service |
How is the Getsystemservice () method implemented?
In the study of Android application framwork layer of source code encountered a problem
is how the Getsystemservice () method in the activity is implemented?
I've been studying for a while, and I didn't see how.
Activity inherits from Contextthemewrapper (only partially implemented), Contextthemewrapper inherits from Contextwrapper,contextwrapper inherits from context
The context is an abstract class, and Getsystemservice is an abstract method.
Did not find out where to implement the abstract method of the context: Getsystemservice AH
Do I think the system will automatically call native to implement this abstract class context?
But how do you know how to achieve the specific experts?
|
Hello, inside the framework layer file Contextimpl.java file
Call the appropriate manager layer based on the type of service
Public Object Getsystemservice (String name) {
if (window_service.equals (name)) {
return Windowmanagerimpl.getdefault ();
} else if (layout_inflater_service.equals (name)) {
Synchronized (Msync) {
Layoutinflater inflater = Mlayoutinflater;
if (inflater! = null) {
return inflater;
}
Mlayoutinflater = Inflater =
Policymanager.makenewlayoutinflater (Getoutercontext ());
return inflater;
}
} else if (activity_service.equals (name)) {
return Getactivitymanager ();
} else if (input_method_service.equals (name)) {
Return inputmethodmanager.getinstance (this);
} else if (alarm_service.equals (name)) {
return Getalarmmanager ();
} else if (account_service.equals (name)) {
return Getaccountmanager ();
} else if (power_service.equals (name)) {
return Getpowermanager ();
}