title: Android : WindowManager﹕ android.view.WindowLeaked: Activity
body: <p>I'm trying to implement for Pop Up window with some buttons.I'm getting the error of <strong>E/WindowManager﹕ android.view.WindowLeaked: Activity</strong> while open the popup window on button click. This is my activity code. The error at this line =   <strong>pwindo.showAtLocation(layout, Gravity.BOTTOM, 0, 0);</strong></p>
  
  <pre><code>private void initiatePopupWindow()
      {
          try
          {
              LayoutInflater inflater = (LayoutInflater) AddPost.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              View layout = inflater.inflate(R.layout.camera_popup, (ViewGroup) findViewById(R.id.popup_element));
              pwindo = new PopupWindow(layout, 700, 380, true);
              pwindo.showAtLocation(layout, Gravity.BOTTOM, 0, 0);
              pwindo.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
  
              btnCamera = (Button) layout.findViewById(R.id.button_Camera);
              btnCamera.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
                      startActivityForResult(cameraIntent, CAMERA_REQUEST);
                  }
              });
  
              btnGallery = (Button) layout.findViewById(R.id.button_Gallery);
              btnGallery.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
  
                      Intent galleryIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                      startActivityForResult(galleryIntent, RESULT_LOAD_IMG);
  
                     }
              });
  
              cancelPopUp = (Button) layout.findViewById(R.id.btnCancelCamera);
              cancelPopUp.setOnClickListener(cancel_button_click_listener);
  
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>Here is my log cat error </p>
  
  <pre><code>10-30 09:56:35.860    6582-6582/? E/WindowManager﹕ android.view.WindowLeaked: Activity com.example.tazeen.classnkk.AddPost has leaked window android.widget.LinearLayout{1cc3bcc6 V.E..... ........ 0,0-700,380 #7f0c0093 app:id/popup_element} that was originally added here
              at android.view.ViewRootImpl.&lt;init&gt;(ViewRootImpl.java:363)
              at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:261)
              at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
              at android.widget.PopupWindow.invokePopup(PopupWindow.java:1058)
              at android.widget.PopupWindow.showAtLocation(PopupWindow.java:887)
              at android.widget.PopupWindow.showAtLocation(PopupWindow.java:851)
              at com.example.tazeen.classnkk.AddPost.initiatePopupWindow(AddPost.java:532)
              at com.example.tazeen.classnkk.AddPost.access$000(AddPost.java:80)
              at com.example.tazeen.classnkk.AddPost$5.onClick(AddPost.java:310)
              at android.view.View.performClick(View.java:4756)
              at android.view.View$PerformClick.run(View.java:19748)
              at android.os.Handler.handleCallback(Handler.java:739)
              at android.os.Handler.dispatchMessage(Handler.java:95)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5254)
              at java.lang.reflect.Method.invoke(Native Method)
              at java.lang.reflect.Method.invoke(Method.java:372)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
  </code></pre>