MainActivity has leaked window

当使用WindowManager 的addView添加界面时,

在释放时,需要调用removeView,否则会出现

has leaked window android.widget.TextView that was originally added  内在泄露错误


@Override

public void onCreate(Bundle savedInstanceState) {
//启动activity时不自动弹出软键盘
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); 
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mListView = (ListView) this.findViewById(R.id.list);
indexBar = (SideBar) findViewById(R.id.sideBar);
mDialogText = (TextView) LayoutInflater.from(this).inflate(R.layout.list_position, null);
head = LayoutInflater.from(this).inflate(R.layout.head, null);
mListView.addHeaderView(head);
mDialogText.setVisibility(View.INVISIBLE);
mWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_APPLICATION,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
mWindowManager.addView(mDialogText, lp);

indexBar.setTextView(mDialogText);

}


@Override
protected void onDestroy() {//我是这样解决了 
mWindowManager.removeView(mDialogText);
super.onDestroy();
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值