android.view.WindowLeaked - 同时使用对话框&新意图

时间:2013-06-25 05:57:40

标签: android

我已经尝试过stackoverflow提供的所有可能的解决方案。但是我仍然在logcat中遇到这个错误:

'活动com.xyz.MainActivity泄露了窗口com.android.internal.policy.impl.PhoneWindow $ DecorView {40d687c0 VE .... R ..... ID 0,0-772,268}那个最初添加在这里'

                    if (Var_place_holder.level == "one")
                    {
                      Var_place_holder.title=obj_itemDetails.getTitle();
                        Var_place_holder.level="two";
                        Intent intent = getIntent();
                        dialog.dismiss();
                        finish();
                        startActivity(intent);} 

                if (Var_place_holder.level == "two")
                  {
                    AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);

                    String Category = Var_place_holder.title;
                    //String IMGURL = obj_itemDetails.getIcon();
                    String Desc = obj_itemDetails.getTitle();

                    alert.setTitle("Detail:");
                    String Msg1 = "Category: " + Category;
                    String Msg2 = "Desc: " + Desc;
                    alert.setMessage(Msg1+"\n"+Msg2+"\n");

                    //alert.setMessage("Price: Rs." + Price);
                    alert.setPositiveButton("Add", new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int whichButton) {
                    //**************************************  
                    //Do something -- TBD
                    //**************************************  
                            dialog.cancel();  

                          }
                        });

                    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                          public void onClick(DialogInterface dialog, int whichButton) {
                    //**************************************  
                    //Do something -- TBD
                    //**************************************  
                            dialog.cancel();

                              }
                            });                         
                    AlertDialog alertDialog = alert.create();
                    alertDialog.show();

                }

以下是我在logcat中收到的错误:

06-25 05:36:50.080: E/WindowManager(2937): Activity com.xyz.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d68560 V.E..... R.....ID 0,0-772,295} that was originally added here
06-25 05:36:50.080: E/WindowManager(2937): android.view.WindowLeaked: Activity com.xyz.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{40d68560 V.E..... R.....ID 0,0-772,295} that was originally added here
06-25 05:36:50.080: E/WindowManager(2937):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:354)
06-25 05:36:50.080: E/WindowManager(2937):  at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:216)
06-25 05:36:50.080: E/WindowManager(2937):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
06-25 05:36:50.080: E/WindowManager(2937):  at android.app.Dialog.show(Dialog.java:281)
06-25 05:36:50.080: E/WindowManager(2937):  at com.xyz.MainActivity$1.onItemClick(MainActivity.java:106)
06-25 05:36:50.080: E/WindowManager(2937):  at android.widget.AdapterView.performItemClick(AdapterView.java:298)
06-25 05:36:50.080: E/WindowManager(2937):  at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
06-25 05:36:50.080: E/WindowManager(2937):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:2749)
06-25 05:36:50.080: E/WindowManager(2937):  at android.widget.AbsListView$1.run(AbsListView.java:3423)
06-25 05:36:50.080: E/WindowManager(2937):  at android.os.Handler.handleCallback(Handler.java:725)
06-25 05:36:50.080: E/WindowManager(2937):  at android.os.Handler.dispatchMessage(Handler.java:92)
06-25 05:36:50.080: E/WindowManager(2937):  at android.os.Looper.loop(Looper.java:137)
06-25 05:36:50.080: E/WindowManager(2937):  at android.app.ActivityThread.main(ActivityThread.java:5041)
06-25 05:36:50.080: E/WindowManager(2937):  at java.lang.reflect.Method.invokeNative(Native Method)
06-25 05:36:50.080: E/WindowManager(2937):  at java.lang.reflect.Method.invoke(Method.java:511)
06-25 05:36:50.080: E/WindowManager(2937):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-25 05:36:50.080: E/WindowManager(2937):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-25 05:36:50.080: E/WindowManager(2937):  at dalvik.system.NativeStart.main(Native Method)

此外,这个错误有多严重?尽管在logcat中出现这个错误,该应用程序似乎工作正常。

TIA

拉​​马纳坦

1 个答案:

答案 0 :(得分:5)

在第一种情况下,你不忘记返回操作员吗?

if (Var_place_holder.level.equals("one")) {
       Var_place_holder.title=obj_itemDetails.getTitle();
       Var_place_holder.level="two";
       Intent intent = getIntent();
       dialog.dismiss();
       finish();
       startActivity(intent);
       return;
} 

现在您正在尝试启动新活动(并停止当前活动),然后准备与第一个已停止活动相关联的ans显示对话框。