进入下一个活动时,活动已经泄露窗口

时间:2015-05-17 22:19:42

标签: android memory dialog

我尝试从Progress Dialogue转到第二activity时显示activity。不幸的是我一直收到这个错误:

05-17 17:58:30.274  29115-29115/me.tb.player E/WindowManager﹕ android.view.WindowLeaked: Activity me.tb.player.SkeletonActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{1ec8d3e2 V.E..... R......D 0,0-1026,288} that was originally added here
            at android.view.ViewRootImpl.<init>(ViewRootImpl.java:363)
            at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:261)
            at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
            at android.app.Dialog.show(Dialog.java:298)
            at me.tb.player.SkeletonActivity$GetProgress.onPreExecute(SkeletonActivity.java:1140)
            at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
            at android.os.AsyncTask.execute(AsyncTask.java:535)
            at me.tb.player.SkeletonActivity$13.onClick(SkeletonActivity.java:1178)
            at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:160)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5254)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)

如果弹出AlertDialog,如果用户点击是,则会转到下一个activity

  private class GetProgress extends AsyncTask<Void, Void, Void> {

        ProgressDialog dialog1;

        protected void onPreExecute() {
            super.onPreExecute();
            if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
                dialog1 = new ProgressDialog(new ContextThemeWrapper(
                        SkeletonActivity.this, android.R.style.Theme_Holo_Light_Dialog));
            } else {
                dialog1 = new ProgressDialog(SkeletonActivity.this);
            }
            dialog1.setCanceledOnTouchOutside(false);
            dialog1.show();
        }

        protected Void doInBackground(Void... params) {
            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    updateScore();
                    clearText();
                    turnComplete();
                }
            });
            return null;
        }

        protected void onPostExecute() {
            dialog1.dismiss();
        }
    }

这是Dialogue

   public void messageAtEndOfTurn(String message) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);

        alertDialogBuilder.setMessage(message);
        alertDialogBuilder.setCancelable(false).setPositiveButton("Yes",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int id) {
                        GetProgress getProgress = new GetProgress();
                        getProgress.execute();
                    }
                }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int id) {
                clear();
            }
        });

        mAlertDialog = alertDialogBuilder.create();

        mAlertDialog.show();
}

我认为问题与进入下一个活动时dismissAlert Dialog没有正确调用有关。或者我的Progress Dialog有错误。有人可以帮忙吗?

或者,当从Progress Dialog转到下一个activity时,是否有更简单的方法来制作AsyncTask - 我真的需要使用#include <cstring> using namespace std; struct Product { char * name; float price; }; int main() { Product * bread = new Product; bread->name = new char[6]; bread->name = "bread"; delete[] bread->name; //!!!THE ERROR OCCURS ON THIS LINE!!! delete bread; } 吗?

1 个答案:

答案 0 :(得分:0)

在完成当前活动之前,您必须先关闭对话框。