I use asynctask to get json data from remote url but sometimes this url return errors in json data like this :
{
   "error": {
      "message": "(#803) Some of the aliases you requested do not exist: RNN.NES",
      "type": "OAuthException",
      "code": 803
   }
}
in doInBackground, i check if there an error by json ..
if(true) {
    //cancel asynctask and show toast with message i use 
    cancel(true)
}
but i do that the condititon is true but it is not cancelled
this is my code :
private class MyAsyncTask extends AsyncTask<String, Void, Void> {
        ProgressDialog mProgressDialog;
        @Override
        protected void onPostExecute(Void result) {
            db = new DAOPages(context);
            db.open();
            db.addPage(name, fid, picName);
            getPagePrefs(fid);
            db.close();
            mProgressDialog.dismiss();
            Intent intent = new Intent(context, PagePrefsActivity.class);
            intent.putExtra("fPageid", fid);
            context.startActivity(intent);
        }
        @Override
        protected void onPreExecute() {
            mProgressDialog = ProgressDialog.show(context, "Loading...",
                    "Data is Loading...");
        }
        @Override
        protected Void doInBackground(String... params) {
            // Creating JSON Parser instance
            JSONParser jParser = new JSONParser();
            // getting JSON string from URL
            JSONObject json = jParser.getJSONFromUrl(params[0]);
            // addPageData(params[0]);
            try {
                if(json.getJSONObject("error") != null) {
                    Log.e("error", "true");
                    cancel(true);
                }
                name = json.getString("name");
                fid = json.getString("id");                                 
                String picture = json.getJSONObject("picture")
                        .getJSONObject("data").getString("url");
                picName = downloadImage(picture, fid);
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }
    }
Now how can i stop that and show toast ???
thanks in advance
 
     
     
    