title: AsyncTask with Glide for clearing Cache
body: <p>It is throwing an error:</p>
  <blockquote>
  <p>Caused by: java.lang.IllegalArgumentException: You must call this method on the main thread</p>
  </blockquote>
  <p>Code:</p>
  <pre><code>Class CacheClearAsyncTask extends AsyncTask&lt;Void, Void, Void&gt; {
  
  
      @Override
      protected Void doInBackground(Void... params) {
          Glide.get(getActivity()).clearDiskCache();
          Glide.get(getActivity()).clearMemory();
  
          return null;
      }
  
      @Override
      protected void onPostExecute (Void result)
      {
          //Toast.makeText(getActivity(), &quot;Cache cleared&quot;, Toast.LENGTH_LONG).show();
      }
  }
  </code></pre>
  <p>Setting preference on click event:</p>
  <pre><code>clearCacheBtnPref=findPreference(getResources().getString(R.string.pref_btn_clear_cache_key));
      clearCacheBtnPref.setOnPreferenceClickListener(new 
  
  Preference.OnPreferenceClickListener() {
                  @Override
                  public boolean onPreferenceClick(Preference preference) {
                      new CacheClearAsyncTask().execute();
                      return true;
                  }
              });
  </code></pre>
  <p>This can not be called in main thread as it is also throws errors and also it does not let me use asynctask.</p>
  <pre><code>    Glide.get(getActivity()).clearDiskCache();
      Glide.get(getActivity()).clearMemory();
  </code></pre>