这是报错信息 android.view.WindowLeaked: Activity com.example.ce.MainActivity has leaked window android.widget.ImageView{50f36bf V.ED.... ........ 0,0-144,144} that was originally added here
一下是浮动框代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
display = getWindowManager().getDefaultDisplay();
width = display.getWidth();
height = display.getHeight();
wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
image = new ImageView(getBaseContext());
image.setBackgroundResource(R.drawable.ic_launcher);
mparams = new WindowManager.LayoutParams();
mparams.width = WindowManager.LayoutParams.WRAP_CONTENT;
mparams.height = WindowManager.LayoutParams.WRAP_CONTENT;
mparams.type = WindowManager.LayoutParams.TYPE_PHONE;
mparams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
mparams.gravity = PixelFormat.RGBA_8888;
mparams.gravity = Gravity.TOP | Gravity.LEFT;
mparams.x = (int) (width/2);
mparams.y = (int) (height/2);
wm.addView(image, mparams);
}
public boolean remove(){
wm.removeView(image);
return true;
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
if (isFinishing()) {
Log.i("TETS", "remove");
remove();
Log.i("TEST", "after remove");
}else{
Log.i("TEST", "activity is close");
}
super.onDestroy();
}
打出的log是remove那边而且也打出了after remove 然后就出现错误信息了这是什么情况啊 我在stop中调用remove的时候也不会出现这个错误啊 只有在destroy中调用remove才会出现错误 该怎么解决啊
ondestory 的時候 activity 已經銷了,但ImageView 沒有被註銷掉
你把ImageView 設為null 試試,沒有過環境沒辦法幫你試