title: Android async task running continuously and not stopping
body: <p>I am using an async task to set wallpaper on menu item click but it keeps on running and does not stop. Here is the code I am using:</p>
  
  <pre><code>class ImageTask extends AsyncTask&lt;Void, Void, Void&gt; {
      Context c;
      ProgressDialog pd;
  
      public ImageTask(Context ctx) { this.c=ctx; }
  
      @Override
      protected void onPreExecute() {
          pd=ProgressDialog.show(c, "Please Wait", "Setting Wallpaper...");
      }
  
      public void onPostExecute() {
          pd.dismiss();
          Toast.makeText(c, "Wallpaper set successfully", Toast.LENGTH_SHORT).show();
      }
  
      protected Void doInBackground(Void... params) {
          WallpaperManager wm1=WallpaperManager.getInstance(c);
  
          try { wm1.setBitmap(ImageFrag1.bmg1); } 
          catch (IOException e) { e.printStackTrace(); }
  
          return null;
      }
  }
  </code></pre>
  
  <p>and in the item selected function I am doing this:</p>
  
  <pre><code>public boolean onOptionsItemSelected(MenuItem item) {
      switch(item.getItemId()) {
          case R.id.action_wall: {
              /*WallpaperManager wm=WallpaperManager.getInstance(getActivity().getApplicationContext());
              try{
                  wm.setBitmap(bmg1);
                  Toast.makeText(getActivity().getBaseContext(), "Wallpaper set successfully",Toast.LENGTH_SHORT).show();
              } catch(IOException e) {
                  oast.makeText(getActivity().getBaseContext(), "Wallpaper not set successfully",Toast.LENGTH_SHORT).show();
              }*/
              ImageTask it1=new ImageTask(getActivity());
              it1.execute();
          }
      }
      return false;   
  }
  </code></pre>
  
  <p>Where am i going wrong?
  Thanks</p>