title: cannot stop asynctask with notification button
body: <p>I'm trying to make app where user is able to take photo and upload it to database using php. I have problem with creating notification which is telling user that photo is being uploaded and giving him possibility to cancel upload from notification.</p>
  
  <p>My code now looks like this :</p>
  
  <pre><code>boolean running = true;
      NotificationCompat.Builder builder;
      NotificationManager NotifyMgr;
  
      @Override
      protected void onCancelled(){
          running = false;
      }
  
      private final BroadcastReceiver receiver = new BroadcastReceiver() {
          @Override
          public void onReceive(Context context, Intent intent) {
              String action = intent.getAction();
  
              if(action.equals("com.app.example.MyServiceClass.STOP")){
                  cancel(true);
                  NotifyMgr.cancel(001);
              }
          }
      };
  
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
  
          Intent intent2 = new Intent();
          intent2.setAction("com.app.example.MyServiceClass.STOP");
          PendingIntent pIntent = PendingIntent.getBroadcast(confirmationActivity.this, 0, intent2, 0);
          builder = new NotificationCompat.Builder(confirmationActivity.this)
                  .setSmallIcon(R.drawable.refresh)
                  .setContentTitle("PhotoApplication")
                  .setContentText("Photo is being uploaded...")
                  .setPriority(NotificationCompat.PRIORITY_HIGH)
                  .addAction(R.drawable.cancel, "Cancel Uploading", pIntent);
  
          IntentFilter filter = new IntentFilter();
          filter.addAction("com.app.example.MyServiceClass.STOP");
          registerReceiver(receiver, filter);
  
          NotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
          NotifyMgr.notify(001, builder.build());
  
          Intent i = new Intent(getApplicationContext(), MainActivity.class);
          i.putExtra("firstTime", false);
          startActivity(i);
      }
  
      protected String doInBackground(String... args) {
          while(running == true) {
              final BitmapFactory.Options options = new BitmapFactory.Options();
              Bitmap secondBitmap = BitmapFactory.decodeFile(filePath, options);
              int height2 = secondBitmap.getHeight() / (secondBitmap.getWidth() / 200);
              secondBitmap = Bitmap.createScaledBitmap(secondBitmap, 200, height2, false);
              String bitmapEncoded2 = encodeTobase64(secondBitmap);
              bitmap = BitmapFactory.decodeFile(filePath, options);
              int height = bitmap.getHeight() / (bitmap.getWidth() / 1080);
              bitmap = Bitmap.createScaledBitmap(bitmap, 1080, height, false);
              String bitmapEncoded = encodeTobase64(bitmap);
              List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
              params.add(new BasicNameValuePair("title", titleq));
              params.add(new BasicNameValuePair("description", descriptionq));
              params.add(new BasicNameValuePair("timestamp", timeStamp));
              params.add(new BasicNameValuePair("photo", bitmapEncoded));
              params.add(new BasicNameValuePair("smallphoto", bitmapEncoded2));
  
              JSONObject json = jsonParser.makeHttpRequest(url_create_product, "POST", params);
  
              Log.d("Create Response", json.toString());
  
              NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(confirmationActivity.this).setSmallIcon(R.drawable.refresh).setContentTitle("PhotoApplication").setContentText("Your photo has been uploaded!");
              Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
              PendingIntent resultPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT);
              mBuilder.setContentIntent(resultPendingIntent);
              int mNotificationId = 002;
              NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
              mNotifyMgr.notify(mNotificationId, mBuilder.build());
  
              running = false;
          }
          finish();
  
          return null;
      }
  
      protected void onPostExecute(String file_url) {
  
      }
  }
  
  class DeleteProduct extends AsyncTask&lt;String, String, String&gt; {
      protected String doInBackground(String... args) {
          int success;
          try {
              List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
              params.add(new BasicNameValuePair("timestamp", timeStamp));
  
              JSONObject json = jsonParser.makeHttpRequest(url_delete_product, "POST", params);
  
              Log.d("Delete Product", json.toString());
  
              success = json.getInt("success");
          } catch (JSONException e){
              e.printStackTrace();
          }
  
          return null;
      }
  }
  </code></pre>
  
  <p>App is fully working, the only thing that app is missing is that working cancel button. It's destroying notification, but photo is being uplaoded anyway.</p>