android-getting Global Context Tips-android learning Journey (68)

Source: Internet
Author: User

We often need to get a global context, such as pop-up toast, launch activities, services, receivers, and their own definition of the control, the operation of the database, the use of notifications, and so the usual method is to call the place to pass the context, sometimes this will not work, Teach you a common way to inherit the application class, and then get static content code such as the following
publicclass MyApplication extends Application{    privatestatic Context context;    @Override    publicvoidonCreate() {        super.onCreate();        context = getApplicationContext();    }    publicstaticgetContext(){        return context;    }}
Well, it needs to be in manifest, if application's property.
application        android:name="com.example.euler_kalvinhe.takephoto.MyApplication"        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >**

android-getting Global Context Tips-android learning Journey (68)

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.