Android Layoutinflater three ways to analyze

Source: Internet
Author: User

There are three different ways to get layoutinflater, so what's the difference between these three ways?

Source:

① Layoutinflater Inflater = layoutinflater.from (context); (Layoutinflater Class)

<span style= "FONT-SIZE:14PX;" >public static Layoutinflater from (context context) {    Layoutinflater layoutinflater =               (layoutinflater) Context.getsystemservice (context.layout_inflater_service);    if (Layoutinflater = = null) {        throw new Assertionerror ("Layoutinflater not Found.")    ;    return layoutinflater;  } </span>

② layoutinflater inflater = Getlayoutinflater (); (activity Class)  

<span style= "Font-size:14px;color: #330033;" >public Layoutinflater Getlayoutinflater () {       return GetWindow (). Getlayoutinflater (); </span>

Public Phonewindow (Context context) {         super (context);         Mlayoutinflater = Layoutinflater.from (context);     }


③ Layoutinflater inflater = (layoutinflater) context.getsystemservice(context.layout_inflater_ SERVICE); (activity Class)  

<span style= "Font-size:14px;color: #330033;" > public static final String Layout_inflater_service = "Layout_inflater";</span>
ps:use with getSystemService(java.lang.String) To retrieve a android.view.LayoutInflater For inflating layout resources in this context.

From the source, three ways in essence are the same, ② is called ① method, and ① is called ③. Java is very interesting is such a tune to the tune, give a person a specious feeling.

For the Getsystemservice class, we can see a lot of service available in the source code:

Window_service (WindowManager) manages the open Windows program Layout_inflater_service (layoutinflater) Gets the Viewactivity_service defined in the XML (Activitymanager)Managing the system state of an application Power_service (Powermanger) Service Alarm_service of power supply (Alarmmanager)Alarm Clock Service Notification_service (Notificationmanager)Service Keyguard_service for status bar (Keyguardmanager)Keypad Lock Service Location_service (Locationmanager)Location of the service Search_service (Searchmanager)Search for service Vebrator_service (Vebrator)Mobile phone Shake service Connectivity_service (Connectivity)Network-connected service Wifi_service (Wifimanager)WiFi Service Telephony_service (Teleponymanager)Telephone service

Not to be continued

Android Layoutinflater three ways to analyze

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.