【发布时间】:2014-06-25 07:10:59
【问题描述】:
我已经创建了一个应用程序,其中用户在他的帐户中登录。为此,我使用了 asyncTask。一切正常,但问题是当我得到响应时,我希望进度条停止。但它会继续进行。
异步任务
protected void onPreExecute() {
super.onPreExecute ();
CommonFunctions.showProgress (c, "Please Wait", true);
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute (s);
try {
JSONObject jsonObject = new JSONObject (s.trim ());
JSONObject NewDataSet = jsonObject.getJSONObject ("NewDataSet");
JSONObject Table = NewDataSet.getJSONObject ("Table");
String User_ID = Table.getString ("User_ID");
String Vendor_IEntity_Code = Table.getString ("Vendor_IEntity_Code");
String Vendor_Name = Table.getString ("Vendor_Name");
// setting the preferences
SettingPreference.setUserId (c, User_ID);
SettingPreference.setVendorId (c, Vendor_IEntity_Code);
SettingPreference.setVendorName (c, Vendor_Name);
} catch (JSONException e) {
e.printStackTrace ();
}
CommonFunctions.showProgress (c, "", false);
Crouton.makeText ((android.app.Activity) c, "Login Sucessful", Style.CONFIRM).show ();
}
@Override
protected String doInBackground(String... strings) {
response = HttpRequest.post ("https://beta135.hamarisuraksha.com/web/WebService/HsJobService.asmx/IsUserValid").send ("_UserID=" + strings[0] + "&_Password=" + strings[1]).body ();
Log.e ("Login Response", "" + response);
return response;
}
常用函数
public class CommonFunctions {
private Context c;
public static void showProgress(Context context, String message, boolean isVisible) {
ProgressDialog progressDialog = new ProgressDialog (context);
progressDialog.setMessage (message);
progressDialog.setCancelable (false);
if (isVisible) {
progressDialog.show ();
} else if (isVisible == false) {
if (progressDialog.isShowing ()) {
progressDialog.dismiss ();
}
}
}
}
【问题讨论】:
标签: android android-asynctask progressdialog