howler2345
Lurker
Hello,
I've been having a ton of trouble getting a login screen to work using ASyncTask. Are there any tutorials or open source apps that I can look at to see what I'm doing wrong. I've looked at every tutorial I could find using Google search with no luck. I just need to look at code that I know works because it seems like there are errors in every tutorial out there according to my personal experience and multiple users having the same issues. Please help!
Thanks!!!!!!!
EDIT: Here is the code that is giving me issues right now:
The parseINT value for result shows as "</table></font>" and throws a system error when trying to log in.
I've been having a ton of trouble getting a login screen to work using ASyncTask. Are there any tutorials or open source apps that I can look at to see what I'm doing wrong. I've looked at every tutorial I could find using Google search with no luck. I just need to look at code that I know works because it seems like there are errors in every tutorial out there according to my personal experience and multiple users having the same issues. Please help!
Thanks!!!!!!!
EDIT: Here is the code that is giving me issues right now:
publicclass LoginTask extends AsyncTask<String, Void, Integer> {
@Override
protected Integer doInBackground(String... arg0)
{
String result ="";
int responseCode = 0;
try
{
HttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.1.115/android/index.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("username", arg0[0]));
nameValuePairs.add(new BasicNameValuePair("password", arg0[1]));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
int executeCount = 0;
HttpResponse response;
do
{
progressDialog.setMessage("Logging in.. ("+(executeCount+1)+"/5)");
// Execute HTTP Post Request
executeCount++;
response = client.execute(httppost);
responseCode = response.getStatusLine().getStatusCode();
Log.d("LoginTask ", "statusCode: " + responseCode);
} while (executeCount < 5 && responseCode == 408);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line;
while ((line = rd.readLine()) != null)
{
result = line.trim();
}
Log.d("LoginTask", "parseINT: " + result);
id = Integer.parseInt(result);
}
catch (Exception e) {
responseCode = 408;
e.printStackTrace();
}
return responseCode;
}
}
The parseINT value for result shows as "</table></font>" and throws a system error when trying to log in.