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)