2017-06-07 2 views
-1

ich einen benutzerdefinierten Fortschrittsdialog haben, die hier überall zu funktionieren scheint, außer in meinem Code:Dialog zeigt nicht über AsyncTask

Meine Login-Aktivität (relevant Snippets):

@Override 
protected void onCreate(Bundle savedInstanceState) { 

    try { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_login); 
     context = this; 
     pd = AUtils.getProgressDialog(context, false); 


       UserExistsAuthenticateAndRoute = getIntent().getBooleanExtra("UserExistsAuthenticateAndRoute", false); 
     RouteToActivity = getIntent().getStringExtra("RouteToActivity"); 

     //make sure there is no token in APrefs in memory during login 
     APrefs pref = new APrefs(); 
     if (pref != null) { 
      pref.putNMToken(null); 
      pref.putNMRefreshToken(null); 
     } 


     ClickableSpan span = new ClickableSpan() { 

      @Override 
      public void onClick(View widget) { 

      } 
     }; 

     setActionBar(); 
     initUi(); 
     mToolbarTitle.setText("Log In"); 
    } catch (Exception exc) { 
     exc.printStackTrace(); 
    } 

} 
     @Override 
     protected Void doInBackground(Void... voids) { 


      GDDataManager.get().login(GDUser, new DataCallBack() { 
         @Override 
         public void update(DataUpdate update) { 

          if (update.code == 0) { 
           final GDUser _gdUser = pref.getMember(); 
           //call get status 
           if (_gdUser != null) { 
            Log.i(TAG, "getUserStatus()"); 
            GDDataManager.get().getUserStatus(_gdUser, new DataCallBack() { 
             @Override 
             public void update(DataUpdate update) { 

              if (update.code == 0) { 
               setGdUserStatus((GDUserStatus) update.data); 
               loginController(getGdUserStatus(), _gdUser); 

              } else { 

               Log.e(TAG, "getUserStatus(), error response msg " + update.message); 
               if (update.message.contains("error")) { 
                App.toast(getString(R.string.general_server_error_message)); 

               } 


              } 
             } 
            }); 
           } 

          } else { 

           Log.e(TAG, "update message:" + update.message); 
           if (update.message.contains("error")) { 
            App.toast(getString(R.string.general_server_error_message)); 
           } else if (update.message.contains("could not verify password")) { 
            App.toast(getString(R.string.could_not_verify_password)); 
           } else if (update.message.contains("no user found")) { 
            App.toast(getString(R.string.no_user_found)); 
           } else { 
            App.toast(update.message); 
           } 

           if (btnLogIn != null) { 
            //disable is valid in order to prevent double click 
            btnLogIn.setEnabled(false); 
            btnLogIn.setTextColor(ContextCompat.getColor(context, R.color.colorGrey)); 
           } 

           edtEmail.setCompoundDrawablesWithIntrinsicBounds(null, null, ContextCompat.getDrawable(context, R.drawable.cross_icon), null); 
           edtEmail.setBackground(ContextCompat.getDrawable(context, R.drawable.textfield_red)); 
           edtPassword.setBackground(ContextCompat.getDrawable(context, R.drawable.textfield_red)); 
          } 

         }//end update getUserStatus 
        } 

      ); 

      return null; 
     } 
    }; 

    try { 
     tryLoginTask.execute(); 
    } catch (Exception exc) { 
     Log.d(TAG, exc.getMessage()); 
     exc.printStackTrace(); 
     //cancel task on exception , DISMISS DIALOG to avoid locking screen 
     tryLoginTask.cancel(true); 
    } 


}//end tryLogin() 

Der statische Code von Dienstprogramm Klasse wurde der Dialog zurückgegeben wird (relevante snippet):

public static Dialog getProgressDialog(Context c, boolean isCancelable) { 

    Dialog pd = new Dialog(c,c.getApplicationInfo().theme); 
    pd.setCanceledOnTouchOutside(isCancelable); 
    pd.requestWindowFeature (Window.FEATURE_NO_TITLE); 
    pd.setContentView (R.layout.progress_dialog); 
    pd.getWindow().setBackgroundDrawable(new ColorDrawable(Color.argb(150,0,0,0))); 

    return pd; 
} 

im sieht keine Fehler, Ausnahmen und der Dialog in anderen Orten showiong mit dem gleichen Ansatz. Manchmal sehe ich es für den Bruchteil einer Sekunde, aber die Aufgabe ist nicht abgeschlossen.

Irgendwelche Vorschläge.

Dank

+0

Jede Chance, Sie sind also, wenn Sie Ihren Dialog in einem AsyncTask zeigen möchten Sie mit runOnUiThread nähern sollte fehlende 'show();' Methode wie 'pd.show();'? – Yupi

+1

Die Methode 'login()' scheint asynchron zu sein, da sie ein Callback-Argument benötigt. Befreien Sie sich von der 'AsyncTask', zeigen Sie Ihren Dialog vor dem' login() 'Aufruf, und schließen Sie ihn in der Callback-Methode ab. –

Antwort

Verwandte Themen