So I have a successful application with a form that registers a user with my website, and I created a 15 frame png animation that also runs well on command.
I have the animation starts up (and is looping) first and then run the HTTP POST at the end of the animation. When the HTTP Post is doing its thing, the animation (pretty much all of android) lags or pauses and then will continue to function after the POST is done.
Is this normal? Is there a way to make it not lag when running the POST?
Thanks!
And for those who are curious, here’s my httpClass (mywebsite.com is just a prop for my actual URL)
try{
Log.d("MYTAG", "Registration begin");
HttpClient client = new DefaultHttpClient();
String postURL = "mywebsite.com";
HttpPost post = new HttpPost(postURL);
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("username", username));
params.add(new BasicNameValuePair("password", password));
params.add(new BasicNameValuePair("email", email));
params.add(new BasicNameValuePair("fullName", fullName));
UrlEncodedFormEntity ent = new UrlEncodedFormEntity(params);
post.setEntity(ent);
HttpResponse responsePOST = client.execute(post);
HttpEntity resEntity = responsePOST.getEntity();
if(resEntity!=null){
newCode = EntityUtils.toString(resEntity);
} else {
newCode = (String) null;
}
}catch(Exception e){
Log.d("MYTAG", "Exception e="+e);
}
return newCode;
}
You can fix that up with an AsyncTask. Google has an introduction to it here. It won’t make things go faster but it will keep your UI thread from stalling out.