Android code optimization----template notation for application nodes

Source: Internet
Author: User

Creates a new class MyApplication, inherited from application. The code is as follows:

Myapplication.java:

1  PackageCom.smyhvae.homepicdemo;2 3 Importandroid.app.Application;4 ImportAndroid.os.Handler;5 ImportAndroid.os.Looper;6 7 /**8 * Created by smyhvae on 2015/5/13.9  */Ten  Public classMyApplicationextendsApplication { One     //gets the context to the main thread A     Private StaticMyApplication Mcontext =NULL; -     //gets the handler to the main thread -     Private StaticHandler Mmainthreadhandler =NULL; the     //gets the looper to the main thread -     Private StaticLooper Mmainthreadlooper =NULL; -     //get to the main thread -     Private StaticThread Mmainthead =NULL; +     //gets the ID to the main thread -     Private Static intMmaintheadid; +  A @Override at      Public voidonCreate () { -         //TODO auto-generated Method Stub -         Super. OnCreate (); -          This. Mcontext = This; -          This. Mmainthreadhandler =NewHandler (); -          This. Mmainthreadlooper =Getmainlooper (); in          This. Mmainthead =Thread.CurrentThread (); -         //Android.os.Process.myUid () Gets the user ID to         //Android.os.Process.myPid () Gets the process ID +         //Android.os.Process.myTid () Gets the ID of the calling thread -          This. Mmaintheadid =Android.os.Process.myTid (); the     } *  $      Public StaticMyApplication getapplication () {Panax Notoginseng         returnMcontext; -     } the  +      Public StaticHandler Getmainthreadhandler () { A         returnMmainthreadhandler; the     } +  -      Public StaticLooper Getmainthreadlooper () { $         returnMmainthreadlooper; $     } -  -      Public StaticThread Getmainthread () { the         returnMmainthead; -     }Wuyi  the      Public Static intGetmainthreadid () { -         returnMmaintheadid; Wu     } -  About}

Then remember to declare it in the manifest file:

 1  <  application  2  = "true"  3   Android:icon  = "@mipmap/ic_launcher"  4   Android: Label  = "@string/app_name"  5  Span style= "color: #ff0000;" > Android:theme  = "@style/apptheme"  6
       Android:name  =". MyApplication "  >  

The property that needs to be declared is the 6th line of Android:name in the code above.

Android code optimization----template notation for application nodes

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.