我正在创建popupwindow
,如下所示
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
LinearLayout linearLayout = new LinearLayout(TimerGameActivity.this);
TextView textView = new TextView(TimerGameActivity.this);
textView.setText("Quit? Score will be lost....");
linearLayout.addView(textView);
PopupWindow popupWindow = new PopupWindow(linearLayout, 200, 100,true);
popupWindow.showAtLocation(linearLayout, Gravity.BOTTOM, 10, 10)
}
但我面临的问题如下。当我按下后退按钮时,它不会让我显示弹出窗口并破坏活动,它会给我以下错误:
04-18 15:04:55.457: E/WindowManager(590): Activity has leaked window android.widget.LinearLayout@44f88be8 that was originally added here
帮帮我。 感谢
答案 0 :(得分:3)
您需要删除:
super.onBackPressed();
答案 1 :(得分:2)
很明显在那里得到一个例外,因为当你按下后退按钮时super.onBackPressed();
被激活,你的Activity将会完成,同时你试图显示一个PopupWindow。因此,没有用于显示PopupWindow的UI。因此,只需删除super.onBackPressed();
并尝试显示PopupWindow
。
答案 2 :(得分:1)
onBackPressed()
将破坏您的活动,同时您参与同一活动进行UI操作,那么它将如何运作?
参考Which actions does the back button/back key on Android trigger?