2013-06-25 46 views
3

我已經嘗試了所有可能的解決方案提供在stackoverflow。但我仍然坐在這個錯誤logcat:android.view.WindowLeaked - 同時使用對話框和新的意圖

'Activity com.xyz.MainActivity has leaked window 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

拉馬納坦

回答

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顯示對話框。

+0

這個伎倆!我有一種感覺,我忽略了一些非常基本的東西。非常感謝您的快速幫助。 – Ramanathan

+0

請標記答案正確。 – Dimmerg

+1

你正在做字符串比較,所以它應該是Var_place_holder.level.equels(「one」); –

相關問題