我尝试在完成后台工作进度停止后开始后台工作时显示进度对话框。对于后台工作,我使用了同步任务类,但未显示我的进度对话框。 以下是我的代码 LoginActivity.java
public class LoginActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loginButton = (Button) findViewById(R.id.btn);
txtUserId = (EditText) findViewById(R.id.username);
txtPassword = (EditText) findViewById(R.id.password);
forgot_pwd = (TextView) findViewById(R.id.forgot_password);
tvError = (TextView) findViewById(R.id.tv_result);
chkRem = (CheckBox) findViewById(R.id.chkRem);
footer = (TextView) findViewById(R.id.footer_login);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (txtUserId.getText().toString().length() == 0) {
return;
}else if (txtPassword.getText().toString().length() == 0) {
return;
}
user = txtUserId.getText().toString();
pwd = txtPassword.getText().toString();
try {
boolean con = isInternetConnected();
Log.d("connection", "" + con);
if (con) {
AsyncTaskCommon atw = new AsyncTaskCommon(LoginActivity.this, user, pwd);
stcode = atw.execute("DoLogin").get();
/*int i = 0;
while (!BaseActivity.baseResponse) {
i++;
}*/
} else {}
} catch (Exception e) { }
if (stcode.equals("0")) {
BaseActivity.sMsg = "";
finish();
Intent m = new Intent(LoginActivity.this, HomePage.class);
startActivity(m);
} else {
BaseActivity.toastValidationMessage(LoginActivity.this,BaseActivity.sMsg);
}
}
});
});
}
}
AsynctaskcommonClass.java
public class AsyncTaskCommon extends AsyncTask<String, Void, String> {
public AsyncTaskCommon(Context context){
this.context = context;
}
public AsyncTaskCommon(Context context, String data, String data1)
{
this.context = context;
AsyncTaskCommon.data = data;
AsyncTaskCommon.data1 = data1;
}
public AsyncTaskCommon(Context context, String mobileno, String smspwd, String emailId)
{
this.context = context;
AsyncTaskCommon.mobileno = mobileno;
AsyncTaskCommon.smspwd = smspwd;
AsyncTaskCommon.emailId = emailId;
}
public AsyncTaskCommon(Context context, String fname, String firmname, String lname, String mobile, String email, String groupId, String patternId)
{
this.context = context;
AsyncTaskCommon.fname = fname;
firm = firmname;
AsyncTaskCommon.email = email;
AsyncTaskCommon.lname = lname;
AsyncTaskCommon.mobile = mobile;
AsyncTaskCommon.groupId = groupId;
AsyncTaskCommon.patternId = patternId;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
ba = new BaseActivity();
BaseActivity.baseResponse = false;
BaseActivity.baseStcode = "";
BaseActivity.sMsg = "";
pleaseWaitDialog = new ProgressDialog(c);
pleaseWaitDialog.setMessage(c.getResources().getString(R.string.waitMsg));
pleaseWaitDialog.setTitle(R.string.app_name);
pleaseWaitDialog.setIndeterminate(true);
pleaseWaitDialog.setIcon(R.drawable.bus1);
pleaseWaitDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
pleaseWaitDialog.setCancelable(true);
pleaseWaitDialog.show();
}
protected void onPostExecute(String resString) {
super.onPostExecute(resString);
if ((pleaseWaitDialog != null) && pleaseWaitDialog.isShowing()) {
pleaseWaitDialog.dismiss();
pleaseWaitDialog = null;
}
}
@Override
protected String doInBackground(String... params) {
methodName = params[0];
resStr = getLoginRequest(data, data1);
List<NameValuePair> params2 = new ArrayList<NameValuePair>();
params2.add(new BasicNameValuePair(BaseActivity.REQUESTATTR, resStr));
resString = ba.sendData(params2,methodName);
try {
JSONObject jsonObject = new JSONObject(resString.substring(resString.indexOf("{"), resString.lastIndexOf("}") + 1));
Log.d("jsonObject", "" + jsonObject);
JSONObject object = jsonObject.getJSONObject("MRRESP");
stcode = object.getString("STCODE");
stmsg = object.getString("STMSG");
BaseActivity.sMsg = stmsg;
BaseActivity.baseStcode = stcode;
Log.d("base stcode in backg", "" + BaseActivity.baseStcode);
}catch(Exception e)
{
e.printStackTrace();
}
BaseActivity.baseResponse = true;
return stcode;
}
private String getLoginRequest(String UserId, String password)
{
}