2015-12-15 182 views
-2

我正在使用ProgressDialog在我的android app中顯示loading頁面。無法顯示進度對話框

我的代碼如下所示:

final ProgressDialog dialog = new ProgressDialog(this); 
      dialog.setCancelable(false); 
      dialog.setMessage("please Wait ..."); 
      dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); 
      dialog.setProgressStyle(R.style.progress_dialog_style); 
      dialog.show(); 
      String toastMsg = null; 
      LoginService loginService = new LoginService(LoginActivity.this); 
      ProfileDetails profileDetails = loginService.checkLogin(mobile_number.getText().toString().trim(), password.getText().toString().trim()); 
      if(profileDetails != null && loginService.changeLogin(MainActivity.LOGIN_YES, mobile_number.getText().toString().trim())) { 
       toastMsg = MainActivity.LOGIN_SUCCESSFUL; 
      } 
    if(profileDetails == null) { 
    runOnUiThread(new Runnable() { 
      public void run() { 
       dialog.dismiss(); 
      } 
     }); 
    } 

,然後我進行一些DB Operations,並得到一些數據

我用dialog.dismiss()

,如果我得到的數據成功地我使用startActivity(intent);

這裏

i)如果我使用dialog.dismiss()當我跑我不能夠看到對話框的代碼。

ii)當我刪除dialog.dimiss()部分我能夠看到對話框但無法關閉它。

請解決此問題。

謝謝

登錄我得到的是

12-16 00:12:42.325 2146-2172/mycompany.com.weekendmovierating W/EGL_emulation﹕ eglSurfaceAttrib not implemented 
12-16 00:12:42.325 2146-2172/mycompany.com.weekendmovierating W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa34423e0, error=EGL_SUCCESS 
12-16 00:12:42.632 2146-2172/mycompany.com.weekendmovierating W/EGL_emulation﹕ eglSurfaceAttrib not implemented 
12-16 00:12:42.632 2146-2172/mycompany.com.weekendmovierating W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xa34422e0, error=EGL_SUCCESS 
12-16 00:12:42.804 2146-2160/mycompany.com.weekendmovierating I/art﹕ WaitForGcToComplete blocked for 58.235ms for cause Background 
12-16 00:12:42.937 2146-2156/mycompany.com.weekendmovierating W/art﹕ Suspending all threads took: 38.186ms 
12-16 00:12:42.938 2146-2160/mycompany.com.weekendmovierating W/art﹕ Suspending all threads took: 19.448ms 
12-16 00:12:42.946 2146-2160/mycompany.com.weekendmovierating I/art﹕ Background sticky concurrent mark sweep GC freed 8670(494KB) AllocSpace objects, 5(100KB) LOS objects, 0% free, 5MB/5MB, paused 21.810ms total 130.763ms 
12-16 00:12:43.105 2146-2160/mycompany.com.weekendmovierating W/art﹕ Suspending all threads took: 61.760ms 
12-16 00:12:43.171 2146-2146/mycompany.com.weekendmovierating I/Choreographer﹕ Skipped 44 frames! The application may be doing too much work on its main thread. 
12-16 00:12:43.245 2146-2160/mycompany.com.weekendmovierating I/art﹕ Background partial concurrent mark sweep GC freed 1796(126KB) AllocSpace objects, 2(76KB) LOS objects, 39% free, 5MB/9MB, paused 12.887ms total 76.159ms 
12-16 00:12:43.803 2146-2172/mycompany.com.weekendmovierating W/EGL_emulation﹕ eglSurfaceAttrib not implemented 
12-16 00:12:43.803 2146-2172/mycompany.com.weekendmovierating W/OpenGLRenderer﹕ Failed to set EGL_SWAP_BEHAVIOR on surface 0xb3fdece0, error=EGL_SUCCESS 
12-16 00:12:44.892 1294-1313/system_process I/ActivityManager﹕ Displayed mycompany.com.weekendmovierating/mycompany.weekendmovierating.activity.SelectLanguageActivity: +2s541ms 
12-16 00:12:45.023 2146-2146/mycompany.com.weekendmovierating I/Choreographer﹕ Skipped 69 frames! The application may be doing too much work on its main thread. 
12-16 00:12:45.055 1545-6738/com.android.inputmethod.latin E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xab7d6dc0 
12-16 00:12:45.082 2146-2172/mycompany.com.weekendmovierating E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xab7da1d0 
12-16 00:12:45.093 2146-2172/mycompany.com.weekendmovierating E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xab7d8870 
12-16 00:12:45.148 2146-2172/mycompany.com.weekendmovierating E/Surface﹕ getSlotFromBufferLocked: unknown buffer: 0xab7d85d0 
12-16 00:12:45.342 2146-2146/mycompany.com.weekendmovierating E/WindowManager﹕ android.view.WindowLeaked: Activity mycompany.weekendmovierating.activity.LoginActivity has leaked window com.android.internal.policy.PhoneWindow$DecorView{ffa0769 V.E...... R......D 0,0-760,192} that was originally added here 
     at android.view.ViewRootImpl.<init>(ViewRootImpl.java:368) 
     at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:299) 
     at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:85) 
     at android.app.Dialog.show(Dialog.java:319) 
     at mycompany.weekendmovierating.activity.LoginActivity.login(LoginActivity.java:87) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at android.view.View$DeclaredOnClickListener.onClick(View.java:4447) 
     at android.view.View.performClick(View.java:5198) 
     at android.view.View$PerformClick.run(View.java:21147) 
     at android.os.Handler.handleCallback(Handler.java:739) 
     at android.os.Handler.dispatchMessage(Handler.java:95) 
     at android.os.Looper.loop(Looper.java:148) 
     at android.app.ActivityThread.main(ActivityThread.java:5417) 
     at java.lang.reflect.Method.invoke(Native Method) 
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 
12-16 00:12:45.371 2146-2156/mycompany.com.weekendmovierating W/art﹕ Suspending all threads took: 25.085ms 
12-16 00:12:45.397 1294-1305/system_process W/WindowManager﹕ Failed looking up window 
java.lang.IllegalArgumentException: Requested window [email protected] does not exist 
     at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8723) 
     at com.android.server.wm.WindowManagerService.windowForClientLocked(WindowManagerService.java:8714) 
     at com.android.server.wm.WindowManagerService.removeWindow(WindowManagerService.java:2697) 
     at com.android.server.wm.Session.remove(Session.java:187) 
     at android.view.IWindowSession$Stub.onTransact(IWindowSession.java:242) 
     at com.android.server.wm.Session.onTransact(Session.java:130) 
     at android.os.Binder.execTransact(Binder.java:453) 

回答

0
runOnUiThread(new Runnable() { 
    @Override 
    public void run() 
    { 
    progress.dismiss(); 
    } 

解散你在運行的線程對話是這樣的。

+0

我用你說的答案測試了我的代碼。在回答 中添加行後,我無法看到「進度對話框」。 –

+0

請在這裏發佈您的完整代碼 – Abhishek

+0

我在我的問題中編輯了以前的代碼。請檢查它 –