title: How can I get current running context in Android?
body: <p>I am trying to get current running context in android, I tried to use:</p>
  
  <pre><code>&lt;application android:name="com.xyz.MyApplication"&gt;
  
  &lt;/application&gt;
  
  public class MyApplication extends Application
  {
      private static Context context;
  
      public void onCreate()
      {
          super.onCreate();
          MyApplication.context = getApplicationContext();
      }
  
      public static Context getAppContext() 
      {
          return MyApplication.context;
      }
  }
  </code></pre>
  
  <p>When I try to use <code>MyApplication.getAppContext()</code>, it gives me the error </p>
  
  <blockquote>
    <p>AndroidRuntime(14421): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application</p>
  </blockquote>