Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to use asynx task to make api connection java

class JSONAsyncTask extends AsyncTask<String, Void, Boolean> {


@Override
protected void onPreExecute() {
    super.onPreExecute();

}

@Override
protected Boolean doInBackground(String... urls) {
    try {

        //------------------>>
        HttpGet httppost = new HttpGet("YOU URLS TO JSON");
        HttpClient httpclient = new DefaultHttpClient();
        HttpResponse response = httpclient.execute(httppost);

        // StatusLine stat = response.getStatusLine();
        int status = response.getStatusLine().getStatusCode();

        if (status == 200) {
            HttpEntity entity = response.getEntity();
            String data = EntityUtils.toString(entity);


            JSONObject jsono = new JSONObject(data);

            return true;
        }


    } catch (IOException e) {
        e.printStackTrace();
    } catch (JSONException e) {

        e.printStackTrace();
    }
    return false;
}

protected void onPostExecute(Boolean result) {

}
Comment

PREVIOUS NEXT
Code Example
Java :: mysqld always running 
Java :: data structure in java 
Java :: output of java file in terminal 
Java :: difference between compile and execute in java 
Java :: unparseable date android 
Java :: java hashmap get nonexistent key 
Java :: find maximum number of rides in amusement park python 
Java :: find node from pos linkedlist java 
Java :: HOW TO CODE WORKING PLUGIN IN MINECRAFT 
Java :: cellrangeaddress in set border example in java 
Java :: spinner android add underline like edittext 
Java :: how to enforce xml dtd validation in java 
Java :: FirebaseCrashlyticsPlugin.java uses or overrides a deprecated API. 
Java :: spigot self cancelling task 
Java :: java join if string is empty delimiter not used 
Java :: java take inpt into arraylist 
Java :: java lambda expressions qunado foi implantada 
Java :: Designing a HashMap Key 
Java :: Java @Retention 
Java :: fog command minecraft 
Java :: java scan next into array 
Java :: How to handle exception if message lost during publishing to kafka 
Java :: time in java 
Java :: Write a java program to merge three singly linked list elements 
Java :: Make device not run on emulator or rooted device 
Java :: password = sdf345 password.isalpha() java 
Java :: Java Insert Elements to LinkedHashSet 
Java :: how to know when user is done typing android 
Java :: camera for barcode android studio 
Java :: How to Fix java.lang.UnsupportedClassVersionError 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =