Example usage for android.net.http HttpResponseCache getInstalled

List of usage examples for android.net.http HttpResponseCache getInstalled

Introduction

In this page you can find the example usage for android.net.http HttpResponseCache getInstalled.

Prototype

public static HttpResponseCache getInstalled() 

Source Link

Document

Returns the currently-installed HttpResponseCache , or null if there is no cache installed or it is not a HttpResponseCache .

Usage

From source file:Main.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private static HttpResponseCache installHttpResponseCache(final File cacheDir) throws IOException {
    HttpResponseCache cache = HttpResponseCache.getInstalled();
    if (cache == null) {
        final long maxSize = calculateDiskCacheSize(cacheDir);
        cache = HttpResponseCache.install(cacheDir, maxSize);
    }/*w  w w. j ava  2  s.  c  o m*/
    return cache;
}

From source file:net.v00d00.xr.HomeActivity.java

@Override
protected void onStop() {
    HttpResponseCache cache = HttpResponseCache.getInstalled();
    if (cache != null) {
        cache.flush();/*from ww w  . j a va 2 s .com*/
    }

    eventBus.unregister(this);
    super.onStop();
}

From source file:com.morlins.artists.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent;//w w  w  .  j a  v a2s.c om
    switch (item.getItemId()) {
    //    
    case R.id.action_about:
        intent = new Intent(MainActivity.this, AboutActivity.class);
        startActivity(intent);
        break;
    //? ?
    case R.id.clear_cache:
        imageLoader.clearDiskCache();
        imageLoader.clearMemoryCache();
        (new AsyncTask<Void, Void, Void>() {
            @Override
            protected Void doInBackground(Void... params) {
                try {
                    clearCache(HttpResponseCache.getInstalled());
                } catch (IOException e) {
                    e.printStackTrace();
                    Log.d("cache cleared", "false");
                }
                return null;
            }

            @Override
            protected void onPostExecute(Void aVoid) {
                super.onPostExecute(aVoid);
                Log.d("cache cleared", "true");
            }
        }).execute();
        break;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.morlins.artists.MainActivity.java

@Override
public void onRefresh() {
    new Handler().post(new Runnable() {
        @Override//w  w  w .  j  av  a2s  . c o  m
        public void run() {
            try {
                clearCache(HttpResponseCache.getInstalled());
            } catch (IOException e) {
                e.printStackTrace();
            }
            artistProvider = new ArtistProvider(getBaseContext(), list, imageLoader, options,
                    mSwipeRefreshLayout);
            artistProvider.execute();
        }
    });
}

From source file:com.fastbootmobile.encore.app.MainActivity.java

@Override
protected void onDestroy() {
    HttpResponseCache cache = HttpResponseCache.getInstalled();
    if (cache != null) {
        cache.flush();//w w  w  .j  a va2  s .  co  m
    }

    // Release services connections if playback isn't happening
    PluginsLookup.getDefault().releasePlaybackServiceIfPossible();
    ImageCache.getDefault().evictAll();
    System.gc();

    super.onDestroy();
}

From source file:com.irccloud.android.activity.UploadsActivity.java

@Override
protected void onDestroy() {
    super.onDestroy();
    if (adapter != null)
        adapter.clear();//from w w w .jav  a  2 s. c  o  m

    if (mDownloadThreadPool != null)
        mDownloadThreadPool.shutdownNow();
    if (Build.VERSION.SDK_INT >= 14) {
        HttpResponseCache cache = HttpResponseCache.getInstalled();
        if (cache != null) {
            cache.flush();
        }
    }
}