4

我已经尝试了 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

拉马纳坦

4

1 回答 1

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;
} 

现在您正在尝试开始新活动(并停止当前活动),然后准备显示附加到第一个已停止活动的对话框。

于 2013-06-25T06:02:34.477 回答