当我要在Window Manager中removeView(View view)
时,我会遇到异常。
wm = (WindowManager) getSystemService(WINDOW_SERVICE);
AntView mView=new AntView(getApplicationContext());
wm.removeView(mView1);
当我尝试上面的代码时,它显示了一个异常:
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)
答案 0 :(得分:0)
您没有将视图添加到wm,sap>
wm = (WindowManager) getSystemService(WINDOW_SERVICE);
AntView mView=new AntView(getApplicationContext());
wm.addView(mView,mViewParams);
wm.removeView(mView1);