Note that there are some explanatory texts on larger screens.

plurals
  1. POAsync in a Async task
    primarykey
    data
    text
    <p>I put the following code in the <code>doInBackground()</code> in another <code>AsyncTask</code> which this <code>HttpPostHandler</code> contain another <code>AsyncTask</code>. Then the <code>handler.get()</code> just keep loading.<br>Anyone got any idea about this? <br>Is this the problem about the threads???</p> <p><strong>Code:</strong></p> <pre><code>@Override protected Void doInBackground(Void... params) { try { champ = Utility.getCounter("test"); this.wait(3); } } catch (InterruptedException e) { e.printStackTrace(); } return null; } </code></pre> <p>In Utility:</p> <pre><code>public static int getCounter(String code) { HttpPostHandler handler = new HttpPostHandler(); try { handler.execute(counter_URL + code); handler.get(); } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } String html = handler.getResultJSONString(); TagNode tagNode; ... } </code></pre> <p>The following is the HttpPostHandler AsyncTask</p> <pre><code> public class HttpPostHandler extends AsyncTask&lt;String, Void, String&gt; { private String url; private String resultJSONString=null; private JSONObject resultJSON; public String getResultJSONString() { return resultJSONString; } public void setResultJSONString(String resultJSONString) { this.resultJSONString = resultJSONString; } private static String toUTF8(InputStream is){ //InputStream is = resEntity.getContent(); InputStreamReader isr = null; StringBuffer buffer = new StringBuffer(); try { isr = new InputStreamReader(is, "utf-8"); Reader in = new BufferedReader(isr); int ch; while((ch = in.read()) != -1){ buffer.append((char)ch); } isr.close(); is.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e){ e.printStackTrace(); } return buffer.toString(); } @Override protected String doInBackground(String... params) { String result = ""; DefaultHttpClient client = new DefaultHttpClient(); try { HttpGet get = new HttpGet(params[0]); HttpResponse response = client.execute(get); Log.d("danny", "response = "+response); HttpEntity resEntity = response.getEntity(); if (resEntity != null) { result = toUTF8(resEntity.getContent()); } } catch (Exception e) { e.printStackTrace(); } finally { client.getConnectionManager().shutdown(); } setResultJSONString(result); return result; } @Override protected void onPostExecute(String result) { // TODO Auto-generated method stub super.onPostExecute(result); resultJSONString = result; } } </code></pre>
    singulars
    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.
 

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