title: Android Refreshing Service after AsyncTask
body: <p>I am trying to re-initiate the entire function of download and uppdate service when an AsyncTask in my activity is being called but I am not sure if I am doing something wrong. Currently, I have a refresh button that initiates the AsyncTask:</p>
  
  <p>Refresh function that initiates AsyncTask:</p>
  
  <pre><code>    final ImageView refreshBtn= (ImageView) findViewById(R.id.spin_refresh);
      Log.i("RootActivity:setupHeader","******ImageView refreshBtn******");
      //Listening to Button Click by User
      refreshBtn.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              // TODO Auto-generated method stub
              Log.i("RootActivity:setupHeader","******OnClick,Call RefreshTask******");
              //CALL ON THE CLASS OF REFRESHTASK ASYNCTASK
              RefreshTask refreshtask = new RefreshTask();
              refreshtask.execute();
          }
      });
  </code></pre>
  
  <p>Once my refresh function is called, it will call onto the refreshtask within my activity:</p>
  
  <pre><code>public class RefreshTask extends AsyncTask &lt;Void,Integer,Long&gt; implements Observer{
  // SET THE PARAMETERS FOR REFRESHTASK IN ASYNCTASK: PRE-EXECUTION, PROGRESS UPDATES &amp; POST-EXECUTION    
  
  private Context context=null;
  private DownloadService callback =null;
  protected boolean exitAsync = false;
  public static Hashtable&lt;String, Download&gt; downloadList;
  final public static String PATH = "/sdcard/DCIM/100MEDIA/";
  private static final Long START_STICKY = null;
  Intent intent;
  ListView lv;
  RelativeLayout rl;
  protected String dSResponse = null;
  
   public void UIThreadProgress(Context context, DownloadService callback) {
          this.context = context;
          this.DownloadService = DownloadService;
      }
  //PROCESS IN CALLING THE DOWNLIST WHILE IN BACKGROUND
  protected Long doInBackground(Void...params){
  
      // TODO Auto-generated method stub
      Log.i("----------RefreshAsyncTask----------", "doInBackground");
  
      try {
          // ====================DownloadService
          Thread.sleep(10000);
          while (this.callback.condition())
          Intent i= new Intent(context.this, UpdateService.class);
          Intent I= new Intent(context.this,DownloadService.class);
          // potentially add data to the intent
          context.this.startService(i); 
          } catch (InterruptedException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
      }while (!exitAsync);    
      return START_STICKY;
  }
  
  @Override
  public void update(Observable observable, Object data) {
      // TODO Auto-generated method stub
      //UpdateServiceStatus
  }
  
  //HANDLES EVENTS ON THE UI-POST-EXECUTE
  @Override
  protected void onPostExecute(Long result){
      super.onPostExecute(result);
      lv.findViewById(R.id.spin_refresh).setVisibility(View.VISIBLE);
      Log.i("----------RefreshAsyncTask----------", "onPostExecute");
      //GIVE FEEDBACK ON THE USER INTERFACE
      Toast.makeText(context, "Your document has been refreshed and contains the updated documents!", Toast.LENGTH_LONG).show();
      // After the process in doInBackground has been completed   
  }
  
  }
  </code></pre>
  
  <p>Please help, I am trying to re-instantiate the download and update service when AsyncTask is being called.</p>