Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a nice class <code>AsyncTask</code> which can be used to easily run asynchronous tasks. If you embed your code in such a subclass, you might end up with this:</p> <pre><code>public class FetchTask extends AsyncTask&lt;Void, Void, JSONArray&gt; { @Override protected JSONArray doInBackground(Void... params) { try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php"); // Add your data List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(2); nameValuePairs.add(new BasicNameValuePair("id", "12345")); nameValuePairs.add(new BasicNameValuePair("stringdata", "AndDev is Cool!")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "iso-8859-1"), 8); StringBuilder sb = new StringBuilder(); sb.append(reader.readLine() + "\n"); String line = "0"; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } reader.close(); String result11 = sb.toString(); // parsing data return new JSONArray(result11); } catch (Exception e) { e.printStackTrace(); return null; } } @Override protected void onPostExecute(JSONArray result) { if (result != null) { // do something } else { // error occured } } } </code></pre> <p>You can start the task using:</p> <pre><code>new FetchTask().execute(); </code></pre> <p>Additional resources:</p> <ul> <li><a href="http://developer.android.com/resources/articles/painless-threading.html" rel="noreferrer">Painless Threading - developer.android.com</a></li> <li><a href="http://developer.android.com/reference/android/os/AsyncTask.html" rel="noreferrer">AsyncTask - developer.android.com</a></li> </ul>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload