Okay I have been trying to get this to work for some time now. I want to be able to have my user login without having the UI hang until the server responds. When the doinbackground is complete I want it to pass an int value or perhaps a boolean value to the postexecute and then the rest of my code will execute. For some reason I have having problems passing values.
Would anyone be able to help me?
private class login extends AsyncTask<Integer, Void, Void>{
ProgressDialog dialog = ProgressDialog.show(MainActivity.this, "", "Loading, Please wait...", true);
String user = "";
@Override
protected int doInBackground(Integer... params) {
// TODO Auto-generated method stub
Log.i("thread", "Doing Something...");
int val = 0;
if(db.userLogin(userTxt.getText().toString(), passTxt.getText().toString(), getApplicationContext()) == "No User Found, please try again!"){
val = 0;
}
return val;
}
protected void onPreExecute(){
//dialog.dismiss();
Log.i("thread", "Started...");
dialog.show();
}
protected void onPostExecute(int result){
Log.i("thread", "Done...");
dialog.dismiss();
if(result == 0){
toast.setText("No User Found, please try again!");
toast.show();
}else{
Intent myIntent = new Intent(ctx, userInfo.class);
myIntent.putExtra("user", user);
startActivityForResult(myIntent, 0);
}
}
}
When using
AsyncTaskyou supply 3 types.The first one is used to pass parameters to the background thread,
the second one is used to pass information when publishing progress, and the third one is used to return information from the background thread to
onPostExecute.You are currently using the first type only.
try:
and then
For more information, see here at the section “AsyncTask’s generic types”.