Android “进度”对话框未显示

Android “进度”对话框未显示,android,Android,我是android新手。我正在创建一个登录机制,当您单击“登录”按钮时,它将调用一个web服务,检查您是否经过身份验证。同时,我希望,只要结果没有从服务返回,那么进度条应该显示,当结果出现时,进度对话框应该消失,我导航到另一个活动,您成功登录,否则会显示一条消息,提示用户名和密码错误。我还想显示一个取消按钮,这样如果身份验证需要很长时间,那么用户可以选择关闭对话框。我试过这个,但我得到了错误 public void onCreate(Bundle savedInstanceState) {

我是android新手。我正在创建一个登录机制,当您单击“登录”按钮时,它将调用一个web服务,检查您是否经过身份验证。同时,我希望,只要结果没有从服务返回,那么进度条应该显示,当结果出现时,进度对话框应该消失,我导航到另一个活动,您成功登录,否则会显示一条消息,提示用户名和密码错误。我还想显示一个取消按钮,这样如果身份验证需要很长时间,那么用户可以选择关闭对话框。我试过这个,但我得到了错误

 public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);

    Button btn_logIn = (Button)findViewById(R.id.btn_signIn );
    btn_logIn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {

            ProgressDialog dialog = new ProgressDialog(getBaseContext());
            dialog.setMessage("Please Wait. Your authentication is in progress");
            dialog.setButton("Cancel", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {                        
                    dialog.dismiss();                       
                }
            }); //end of anonymous class

            dialog.show();              
        }           
    }); //end of anonymous class    
} //end of onCreate()
当我点击登录按钮时,我会收到一条消息,强制关闭应用程序。我没有使用onCreateDialogint id方法,因为我在developer.android.com上读到

Opening a progress dialog can be as simple as calling ProgressDialog.show(). For
example, the progress dialog shown to the right can be easily achieved without
managing the dialog through the onCreateDialog(int) callback, as shown here:

ProgressDialog dialog = ProgressDialog.show(MyActivity.this, "", 
                    "Loading. Please wait...", true);
请看,它说不需要使用onCreateDialog进行进度对话框。没有 通过onCreateDialogint回调管理对话框。在我的案例中如何显示对话框。
如果您想使用getBaseContext或与此相关的对话框,请使用

 ProgressDialog dialog = new ProgressDialog(view.getBaseContext());

另一种方式是

如上所述

  ProgressDialog dialog = new ProgressDialog(YourRecentActivity.this);

尝试使用新的ProgressDialogy来完成当前的活动;而不是新的ProgressDialoggetBaseContext;谢谢:它成功了。为什么现在使用getBaseContext呢?另外,我想问一下“取消”按钮,单击“取消”按钮是否可以呼叫“解雇”或我是否应该呼叫“取消”?谢谢
 ProgressDialog dialog = new ProgressDialog(view.getApplicationContext());
  ProgressDialog dialog = new ProgressDialog(YourRecentActivity.this);