0
我犯了一個小的應用程序,其中我打開一個新的觀點與TYPE_SYSTEM_OVERLAY,現在我想通過點擊關閉的按鈕,我得到了錯誤:的Android,viewClass類滲漏窗口
Activity com.example.viewandbutton.View2Class has leaked window [email protected] that was originally added here
我已經搜索了錯誤,並發現我必須dismiss()
的活動,但解僱只適用於Dialog對象,所以我不知道如何停止活動。
這裏是我的代碼:
public class View2Class extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.view2);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View myView = inflater.inflate(R.layout.view2, null);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
final WindowManager wm = (WindowManager) this.getSystemService(WINDOW_SERVICE);
wm.addView(myView, params);
Button btnActivity = (Button)findViewById(R.id.button2);
btnActivity.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
finish();
}
});
}
}
的感謝!
按我的意見ü需要在停止刪除視圖或者點擊按鈕:嘗試這個'wm.removeView(myView);' –
wm.removeView應該在完成之前調用() – Sanjeev
爲什麼你要再次膨脹相同的佈局? –