title: Dialog throwing "Unable to add window — token null is not for an application”
body: <p>My code:</p>
  
  <pre><code>
      public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          NoticeBoard.init(MainActivity.this);
          NoticeBoard.getInstance().setButton();
          setContentView(NoticeBoard.getInstance());
      }
  
  }
  
      public class NoticeBoard extends ImageView {
      private static NoticeBoard instance = null;
      private static Paint paint;
      protected  Context mContext;
      private static WindowManager mWindowManager;
  
      public NoticeBoard(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      public static NoticeBoard getInstance() {
          return instance;
      }
  
      public static void init(Context context) {
          instance = new NoticeBoard(context);
          instance.setImageResource(R.drawable.ic_launcher);
          instance.invalidate();
      }
  
      public NoticeBoard(Context context) {
          super(context);
          mWindowManager = (WindowManager) getContext().getApplicationContext().getSystemService(Context.WINDOW_SERVICE); 
          mContext = context;
          setBackgroundColor(Color.BLACK);
      }
  
      @Override
      protected void onDraw(Canvas canvas) {
          super.onDraw(canvas);
          paint = new Paint(Paint.LINEAR_TEXT_FLAG);
          paint.setColor(Color.GRAY);
          paint.setTextSize(12.0F);
          canvas.drawText("Hello World", 100, 200, paint);
      }
  
      @Override
      public boolean onTouchEvent(MotionEvent event) {
          return super.onTouchEvent(event);
      }
  
      public void setButton() {
          Activity a =(Activity) mContext;
          ImageButton btn = new ImageButton(a);
          btn.setBackgroundResource(R.drawable.ic_launcher);
          android.view.WindowManager.LayoutParams paramsSplit = new android.view.WindowManager.LayoutParams();
          paramsSplit.width=2;
          paramsSplit.height=2;
          instance.mWindowManager.addView(btn, paramsSplit);
      }
  }
  </code></pre>
  
  <p>I tried to find the answer, I changed getApplicationContext() to MainActivity.this, and changed context to (Activity)Context, but it still is not working. What's wrong with it?
  Ps.I'm Chinese, and my english is not very good. Thanks for your help.</p>