2012-09-07 207 views
0

我的應用程序仍在顯示處理狀態,但我轉到另一個屏幕並註銷仍在處理的進程對話框沒有停止它。登錄後和註銷時,進程對話框不會停止

當我按在登錄頁面登錄按鈕,我用這個代碼:

btnLogin.setOnClickListener(new OnClickListener() { 

    public void onClick(View view) { 

     showProgress(); 
     postLoginData(); 

    } 
}); 

public void postLoginData() { 

    if (pin.getTextSize() == 0 || mobile.getTextSize() == 0) { 

     AlertDialog.Builder altDialog = new AlertDialog.Builder(this); 
     altDialog.setMessage("Please Enter Complete Information!"); 

    } else { 
     Intent i = new Intent(this.getApplicationContext(), 
     AgAppMenu.class); 
     Bundle bundle = new Bundle(); 
     bundle.putString("mno", mobile.getText().toString()); 
     bundle.putString("pinno", pin.getText().toString()); 

     i.putExtras(bundle); 
     startActivity(i); 
    } 
} 

private void showProgress() { 
    myProgressDialog = ProgressDialog.show(LoginScreen.this, null, "Processing please wait...", true); 
} 

回答

0

你應該處理myProgressDialog.dismiss()爲好。 比如從處理程序等控制它..

如果你想從另一個活動關閉此對話框,最好設置在此活動static Handler,讓其他活動可以使用static HandlersendEmptyMessage將其關閉。

+0

如果我使用myProgressDialog.dismiss() 在此位置 意圖I =新意圖(this.getApplicationContext(),AgAppMenu.class); \t \t \t Bundle bundle = new Bundle(); \t \t \t bundle.putString(「mno」,mobile.getText()。toString()); \t \t \t bundle.putString(「pinno」,pin.getText()。toString()); \t \t \t \t \t i.putExtras(bundle); \t \t \t myProgressDialog.dismiss(); \t \t \t startActivity(i); processdailog沒有顯示 –

+0

因爲它太快了,showProgress();然後myProgressDialog.dismiss(); ,或者你可以使用postDelayed在一定時間後關閉它。 –

+0

帶有Runnable的處理程序'postDelayed'可在一定的時間內解除它。 –

0
private void showProgress() 
    {  
     m_ProgressDialog = ProgressDialog.show(YourActivity.this,"Please wait...", "Saving And Sending Record ...", true); 
       new Thread() { public void run() {try{sleep(5000);} catch (Exception e) { }}}.start(); 
    }