Skip to content Skip to sidebar Skip to footer

Android Freeze Screen 20 Seconds After Execute A Http Post

I'm executing a HTTP Post from my android device, but for some reason, the post is executed in few seconds but the screen is still freeze for 18 or 20 seconds more. The code that I

Solution 1:

classCheckextendsAsyncTask<String, Integer, Boolean> {

    @OverrideprotectedBooleandoInBackground(String... params) {



            //Add main arguments here; Connection that reffers to other methods but String queryString = RewriteParams(params);
    url = BaseURL + url + queryString;
    HttpClient httpclient = newDefaultHttpClient();
    HttpPost httppost = newHttpPost(url);

    try {

        httppost.setEntity(newUrlEncodedFormEntity(params));
        HttpResponse response = httpclient.execute(httppost);

        returntrue;
    } catch (ClientProtocolException e) {
        returnfalse;
    } catch (IOException e) {
        returnfalse;
    }
        returnnull;
    }
}

and execute like so:

newCheck().execute("http://website.com");

You can add URL there if you want. If it is a fixed link it is not nessesary.

You added so you can run connection stuff on the main thread, but I believe your thread isn't properly built for it. It can be explained like this:

while(bool = true){
    connection code
}
rendering code

While it is connecting and doing all of that, the other tasks cannot execute due to the connections requirements. Running async allows you to connect without it disturbing the main thread.

If you need different arguments than String, Integer and Boolean, remember that the first variable is the one that is params in doInBackground and the last argument will be the return value

Post a Comment for "Android Freeze Screen 20 Seconds After Execute A Http Post"