Note that there are some explanatory texts on larger screens.

plurals
  1. POAsyncTask not cancelling in android
    primarykey
    data
    text
    <p>I have an Async task in my main activity which runs when I press a button. Now for some reason if the request takes too long(due to the server being unavailable) I am unable to even close the activity using the back button. Does anyone know why this is happening? From this <a href="https://stackoverflow.com/questions/6023350/android-asynctask-blocks-back-key-dispatch-event">Android AsyncTask blocks back key dispatch Event</a> I understand that the back button should automatically kill my activity and finish the async task. But that does not seem to be happening. The only way I can come out of the activity is by pressing the home button on my android phone which of course simply saves the state so once I open up the activity again the async task still continues to execute.</p> <pre><code>class mytask extends AsyncTask&lt;Void,Void,String&gt; { HttpResponse response; @Override protected void onPreExecute() { // TODO Auto-generated method stub super.onPreExecute(); } @Override protected String doInBackground(Void... arg0) { // TODO Auto-generated method stub Log.d("In","IN"); HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("someurl"); try { // Add your data List&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(); nameValuePairs.add(new BasicNameValuePair("name", "somename")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); response = httpclient.execute(httppost); p=inputStreamToString(response.getEntity().getContent()).toString(); return p; } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } return null; } protected void onPostExecute(String result) { // TODO Auto-generated method stub super.onPostExecute(result); } } </code></pre>
    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.
 

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