2

我正在创建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

帮帮我。谢谢

4

3 回答 3

3

您需要删除:

super.onBackPressed();
于 2012-04-18T10:00:08.810 回答
2

很明显会出现异常,因为当您按下后退按钮时super.onBackPressed();,您的 Activity 将完成,同时您试图显示一个 PopupWindow。因此,没有用于显示 PopupWindow 的 UI。因此,只需删除super.onBackPressed();并尝试显示PopupWindow

于 2012-04-18T10:07:27.407 回答
1

onBackPressed()将破坏您的活动,同时您参考同一活动进行 UI 操作,那么它将如何工作?

参考Android 上的后退按钮/后退键会触发哪些操作?

于 2012-04-18T10:01:50.610 回答