无法显示进度对话框

时间:2015-12-15 18:38:40

标签: android dialog progressdialog

我正在使用ProgressDialogloading中显示android app页面。

我的代码如下:

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 android.os.BinderProxy@aa60cd1 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)

1 个答案:

答案 0 :(得分:0)

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

在runnable thread中以这样的方式关闭你的对话框。