Get Context globally

  1. Create a class extends Application

public class SpeechApplication extends Application {
   private static Context mContext;
   @Override
public void onCreate() {
      super.onCreate();
      mContext = getApplicationContext();
   }

   public static Context getContext() {
      return mContext;
   }
}

 

2. Register   android :name= "xxxxx" under the application tag in AndroidManifest.xml 

 

<application
android:name="com.aispeech.SpeechApplication"
     .....

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326307606&siteId=291194637