I am new to android. I am making a log in mechanism that when you click on Log In button then it call a web service, which check you are authenticated or not. Meanwhile i want that as long as result is not return from the service, then the progress bar should be shown, and when result come then progress dialog should be disappear and i navigate to another activity that you successfully login else show a message that sorry wrong username and password. I also want to show a cancel button so if authentication takes long then user has the option to dismiss the dialog. I tried this but i am getting error.
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()
When i click on login button then i get message that force close application. I didn't use the onCreateDialog(int id)
method because i read that on developer.android.com that
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);
See it is saying no need to use onCreateDialog() for Progress Dialog. without
managing the dialog through the onCreateDialog(int) callback
. How can i show the dialog in my case.
Thanks