弹出框+清除缓存

private void showClearCacheDialog() {
    new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT).setTitle("清理缓存")
            .setNegativeButton("取消", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).setPositiveButton("确定", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            clearCache();
            dialog.dismiss();
        }
    }).show();
}
/**
 * 清理缓存文件夹下的所有文件
 */
private void clearCache() {
    File cacheDir = this.getCacheDir();
    if (cacheDir != null && cacheDir.exists() && cacheDir.isDirectory()) {
        for (File item : cacheDir.listFiles()) {
            item.delete();
        }
    }
}

你可能感兴趣的:(弹出框+清除缓存)