I've looked at so many questions and answers but none of what i found has actually worked!
So basically if the title doesn't help much then what I'm trying to do is execute an AsyncTask from a dialog but it's not executing and when it does, it'll show up as an null object and if I'm honest it's bloody annoying!
So if anyone can help then that would be great.
The Class is subbed.
Here's the Async class:
static class UpdatePassword extends AsyncTask<String, String, String> {
Context context;
String oldPassword;
String newPassword;
public UpdatePassword(String setOldPassword, String setNewPassword, Context context) {
this.oldPassword = setOldPassword;
this.newPassword = setNewPassword;
this.context = context;
}
@Override protected String doInBackground(String... params) {
HttpRequestUtils httpRequestUtils = new HttpRequestUtils(context);
if (TextUtils.isEmpty(oldPassword) || TextUtils.isEmpty(newPassword)) {
return null;
} else {
String response = null;
String baseUrl = "rest/ws/user/update/password";
ApiResponse apiResponse = null;
try {
response = httpRequestUtils.getResponse(baseUrl + "?oldPassword=" + oldPassword + "&newPassword=" + newPassword, "application/json", "application/json");
if (TextUtils.isEmpty(response)) {
return null;
}
apiResponse = (ApiResponse) GsonUtils.getObjectFromJson(response, ApiResponse.class);
if (apiResponse != null && apiResponse.isSuccess()) {
return apiResponse.getStatus();
}
Log.i("Update", "password call" + apiResponse);
} catch (Exception e) {
e.printStackTrace();
}
return newPassword;
}
}
}
And here's what I'm doing to execute it:
String oldPassword = changePassOld.getText().toString();
String newPassword = changePassNew.getText().toString();
AsyncTask task = new UpdatePassword(oldPassword, newPassword, ProfileFragment.this.getContext());
task.execute();
Edit: I have noticed that i only have doInBackground
but even when i had preExecute
, it still wouldn't work