0

I am getting exception when i am going to removeView(View view) in the Window Manager.

wm = (WindowManager) getSystemService(WINDOW_SERVICE);
AntView mView=new AntView(getApplicationContext());
wm.removeView(mView1);

When i try the above code it shows me an Exception:

Caused by: java.lang.IllegalArgumentException: View not attached to window manager
    at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:381)
    at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:226)
    at com.example.testactivity.BackService.onStartCommand(BackService.java:63)
0   at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:2051)
bakriOnFire
  • 2,685
  • 1
  • 15
  • 27
Sumit Kandoi
  • 427
  • 4
  • 12

1 Answers1

0

You didnt add mView to wm, so:

wm = (WindowManager) getSystemService(WINDOW_SERVICE);
AntView mView=new AntView(getApplicationContext());
wm.addView(mView,mViewParams);

wm.removeView(mView1);
lpk
  • 1