Android's Getsystemservice

Source: Internet
Author: User

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 ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.