This is my AsyncTask class
private class UpdatingNews extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
webservice.UpdateAllNews();
webservice.updateallCatNews();
return null;
}
@Override
protected void onPostExecute(String result) {
}
}
i call it by
UpdatingNewsupdate = new UpdatingNews();
update.execute();
It does excecute. Then i want to check the status of this task has finish or not when i click button so i check like this.
if (update.getStatus().toString()
.equals(AsyncTask.Status.FINISHED.toString())) {
toast = Toast.makeText(Main_FormNewUser.this,
"Thanks for fill in our survey form!",
Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL
| Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
name = nametext.getText().toString();
email = emailtext.getText().toString();
webservice.InsertSurvey(name, email, ages, genders,
jobs, salaries, interesting);
webservice.insertFormSubmit(1);
startActivity(new Intent(Main_FormNewUser.this,
Main_AllLatestNews.class));
finish();
}
After i clicked, it will start Main_AllLatestNews.class but with NullPointerException.
I try not use AsyncTask and return me no error, i got no idea why i call AsyncTask it will give me error?
Understand the basics of AsyncTask Check this blog. Painless Threading or AsyncTask
You have not accept the return from doInBackground() in onPostExecute(String result)
doInBackground() return the result to onPostExecute. So you have to update the values or the UI that you want here in onPostExecute only.