Skip to content Skip to sidebar Skip to footer

Http Post Request Android 4 (working In 2.3)?

Ok so, here is the deal, I've coded an app that requests via HTTP (post) data from a web url, the data is returned using JSon arrays and i parse those arrays to get what i want. Up

Solution 1:

You need to put this in an Async task, it will not run in the main thread in 3.0 >

use this:

publicclassPostTaskextendsAsyncTask<Void, String, Boolean> {

        @OverrideprotectedBooleandoInBackground(Void... params) {
            boolean result = false;

            //All your code goes in here //If you want to do something on the UI use progress updatepublishProgress("progress");
            return result;
        }

        protectedvoidonProgressUpdate(String... progress) {
            StringBuilder str = newStringBuilder();
                for (int i = 1; i < progress.length; i++) {
                    str.append(progress[i] + " ");
                }

        }
    }

You need a reference to it outside the async task

PostTask posttask;

then you need to start it

posttask = newPostTask();
posttask.execute();

I had the exact same problem a couple of days ago, goodluck

Solution 2:

With Android 4.0 you cant use http connection without using a Thread (with a runnable, asyinctask ... )

The best you can do is implements a Thread but if you cant do it you cant delete in the android manifest android:targetVersion="14".

If you need some elements of the version 14/higher like Holo theme or something you can configure in

Right clink in the project --> Propierties --> Android --> Project Built Target = 14 or that you want

Post a Comment for "Http Post Request Android 4 (working In 2.3)?"