Okay, this has me confused once again. I am trying to either A: set a golbal variable, which i can do or B: retieve a variable from my AsyncTask. I have set can set the golbal variable from asynctask which is fine, but the activity calls it before it is set with the asynctask.
So therefore I need the application to finsh the AsyncTask before calling the golbal variable.
new createUser().execute();
Log.i("res", "After: " + Boolean.toString(MyProperties.getInstance().valut));
private class createUser extends AsyncTask<Void, Void, Boolean> {
ProgressDialog dialog = ProgressDialog.show(MainActivity.this, "",
"Creating User...", true);
Toast toast = Toast.makeText(getApplicationContext(), "",
Toast.LENGTH_SHORT);
@Override
protected Boolean doInBackground(Void... params) {
// TODO Auto-generated method stub
if (db.createUser(nameU.getText().toString(), userU.getText()
.toString(), emailU.getText().toString(), passU.getText()
.toString()) == false) {
return false;
} else {
return true;
}
}
protected void onPreExecute() {
dialog.show();
}
protected void onPostExecute(Boolean result) {
dialog.dismiss();
if (!result) {
toast.setText("User already exists!");
toast.show();
res = result;
MyProperties.getInstance().valut = res;
Log.i("res", Boolean.toString(MyProperties.getInstance().valut));
} else {
toast.setText("Success");
toast.show();
res = result;
MyProperties.getInstance().valut = res;
Log.i("res", Boolean.toString(MyProperties.getInstance().valut));
}
}
}
Work with your global variable in
onPostExecutemethod of yourAsyncTask. You need to implement it in yourAsyncTask‘s child. This method is called then all work is done.EDIT