Note that there are some explanatory texts on larger screens.

plurals
  1. POBack button only dismissing Progress Dialog and not the AsyncTask
    text
    copied!<p>I am trying to cancel my aynctask when the user hits the back button. I have done my research on which methods to use for this operation and I found it difficult to figure out why are there more than one method. I have found one method and tried it but it only dismisses my ProgressDialog and my aynctassk still executes. So can somebody assist me with this issue of getting my asynctask to dismiss the proper way. </p> <pre><code>@Override public void onBackPressed() { /** If user Pressed BackButton While Running Asynctask this will close the ASynctask. */ if (mTask != null &amp;&amp; mTask.getStatus() != AsyncTask.Status.FINISHED) { mTask.cancel(true); } super.onBackPressed(); finish(); } @Override protected void onDestroy() { // TODO Auto-generated method stub /** If Activity is Destroyed While Running Asynctask this will close the ASynctask. */ if (mTask != null &amp;&amp; mTask.getStatus() != AsyncTask.Status.FINISHED) { mTask.cancel(true); } super.onDestroy(); } @Override protected void onPause() { // TODO Auto-generated method stub if (pDialog != null) { if(pDialog.isShowing()) { pDialog.dismiss(); } super.onPause(); } } </code></pre> <p>And please let me know If I need to post my <code>doInBackGround</code> method to the question</p> <pre><code>protected String doInBackground(String... args) { try { Intent in = getIntent(); String searchTerm = in.getStringExtra("TAG_SEARCH"); String query = URLEncoder.encode(searchTerm, "utf-8"); String URL = "http://example.com"; JSONParsser jParser = new JSONParsser(); JSONObject json = jParser.readJSONFeed(URL); try { JSONArray questions = json.getJSONObject("all").getJSONArray("questions"); for(int i = 0; i &lt; questions.length(); i++) { JSONObject question = questions.getJSONObject(i); String Subject = question.getString(TAG_QUESTION_SUBJECT); String ChosenAnswer = question.getString(TAG_QUESTION_CHOSENANSWER); String Content = question.getString(TAG_QUESTION_CONTENT); HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;(); map.put(TAG_QUESTION_SUBJECT, Subject); map.put(TAG_QUESTION_CONTENT, Content); map.put(TAG_QUESTION_CHOSENANSWER, ChosenAnswer); questionList.add(map); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } </code></pre>
 

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