Android之针对webview的缓存
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.apache.http.Header;
import android.app.Activity;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Environment;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.lee.webviewcache.utils.ASimpleCacheUtil;
import com.lee.webviewcache.utils.ExecutorServiceUtil;
import com.lee.webviewcache.utils.TAsyncRestClientUtil;
import com.loopj.android.http.AsyncHttpResponseHandler; public class MainActivity extends Activity { private final static String url = "http://www.baidu.com";
private WebView mWebView;
private ASimpleCacheUtil mAcache;
private Context mContext;
private String cacheData;
private String jsCacheData; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); mContext = this;
mAcache = ASimpleCacheUtil.get(mContext); initData(); initView(); asyncGetHtmlLocalFile();
} private void initData() {
cacheData = mAcache.getAsString("Html-Content");
jsCacheData = mAcache.getAsString("javascript_get_data");
} private void initView() {
mWebView = (WebView) findViewById(R.id.webView);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new JIFaceClient(), "droid"); mWebView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
} @Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url); String ht = "javascript:window.droid.print(document.getElementsByTagName('html')[0].innerHTML);";
view.loadUrl(ht);
} }); if (isNetworkConnected()) {
mWebView.loadUrl(url);
} else {
// 1.读取本地html文件
// mWebView.loadUrl("file:///" +
// Environment.getExternalStorageDirectory().getPath() +
// "/myHtml.html"); // 2.读取html data
// if (cacheData!=null) {
// mWebView.loadDataWithBaseURL("", cacheData, "text/html",
// "UTF-8","");
// } // 3.读取javascript html data
// if (jsCacheData!=null) {
// mWebView.loadDataWithBaseURL("", jsCacheData, "text/html",
// "UTF-8","");
// } } } private void asyncGetHtmlLocalFile() {
TAsyncRestClientUtil.get(url, null, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers,
final String content) {
// TODO Auto-generated method stub
super.onSuccess(statusCode, headers, content);
if (content != null && !content.trim().equals("")) {
mAcache.put("Html-Content", content); ExecutorServiceUtil.getExecutorServiceInstance().submit(
new Runnable() { @Override
public void run() {
writeFileToSDCard("myHtml.html", content); }
}); }
}
});
} private boolean isNetworkConnected() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
return ni != null && ni.isConnectedOrConnecting();
} private void writeFileToSDCard(String fileName, String content) {
File file = new File(Environment.getExternalStorageDirectory(),
fileName);
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(file);
outputStream.write(content.getBytes());
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
outputStream.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
mWebView.goBack();
return true;
}
return super.onKeyDown(keyCode, event);
} // jsan
class JIFaceClient {
public void print(String data) {
mAcache.put("javascript_get_data", data);
}
}
}
public class ASimpleCacheUtil {
public static final int TIME_MIN_10 = 60 * 20;
public static final int TIME_HOUR = 60 * 60;
public static final int TIME_DAY = TIME_HOUR * 24;
private static final int MAX_SIZE = 1000 * 1000 * 50; // 50 mb
private static final int MAX_COUNT = Integer.MAX_VALUE; // �����ƴ����ݵ�����
private static Map<String, ASimpleCacheUtil> mInstanceMap = new HashMap<String, ASimpleCacheUtil>();
private ASimpleCacheUtilManager mCache; public static ASimpleCacheUtil get(Context ctx) {
return get(ctx, "ASimpleCacheUtil");
} public static ASimpleCacheUtil get(Context ctx, String cacheName) {
File f = new File(ctx.getCacheDir(), cacheName);
return get(f, MAX_SIZE, MAX_COUNT);
} public static ASimpleCacheUtil get(File cacheDir) {
return get(cacheDir, MAX_SIZE, MAX_COUNT);
} public static ASimpleCacheUtil get(Context ctx, long max_zise, int max_count) {
File f = new File(ctx.getCacheDir(), "ASimpleCacheUtil");
return get(f, max_zise, max_count);
} public static ASimpleCacheUtil get(File cacheDir, long max_zise, int max_count) {
ASimpleCacheUtil manager = mInstanceMap.get(cacheDir.getAbsoluteFile() + myPid());
if (manager == null) {
manager = new ASimpleCacheUtil(cacheDir, max_zise, max_count);
mInstanceMap.put(cacheDir.getAbsolutePath() + myPid(), manager);
}
return manager;
} private static String myPid() {
return "_" + android.os.Process.myPid();
} private ASimpleCacheUtil(File cacheDir, long max_size, int max_count) {
if (!cacheDir.exists() && !cacheDir.mkdirs()) {
throw new RuntimeException("can't make dirs in "
+ cacheDir.getAbsolutePath());
}
mCache = new ASimpleCacheUtilManager(cacheDir, max_size, max_count);
} // =======================================
// ============ String���? ��д ==============
// =======================================
/**
* ���� String���? �� ������
*
* @param key
* �����?key
* @param value
* �����?String���?
*/
public void put(String key, String value) {
File file = mCache.newFile(key);
BufferedWriter out = null;
try {
out = new BufferedWriter(new FileWriter(file), 1024);
out.write(value);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
mCache.put(file);
}
} /**
* ���� String���? �� ������
*
* @param key
* �����?key
* @param value
* �����?String���?
* @param saveTime
* �����ʱ��?��λ����
*/
public void put(String key, String value, int saveTime) {
put(key, Utils.newStringWithDateInfo(saveTime, value));
} /**
* ��ȡ String���?
*
* @param key
* @return String ���?
*/
public String getAsString(String key) {
File file = mCache.get(key);
if (!file.exists())
return null;
boolean removeFile = false;
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader(file));
String readString = "";
String currentLine;
while ((currentLine = in.readLine()) != null) {
readString += currentLine;
}
if (!Utils.isDue(readString)) {
return Utils.clearDateInfo(readString);
} else {
removeFile = true;
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (removeFile)
remove(key);
}
} // =======================================
// ============= JSONObject ���? ��д ==============
// =======================================
/**
* ���� JSONObject���? �� ������
*
* @param key
* �����?key
* @param value
* �����?JSON���?
*/
public void put(String key, JSONObject value) {
put(key, value.toString());
} /**
* ���� JSONObject���? �� ������
*
* @param key
* �����?key
* @param value
* �����?JSONObject���?
* @param saveTime
* �����ʱ��?��λ����
*/
public void put(String key, JSONObject value, int saveTime) {
put(key, value.toString(), saveTime);
} /**
* ��ȡJSONObject���?
*
* @param key
* @return JSONObject���?
*/
public JSONObject getAsJSONObject(String key) {
String JSONString = getAsString(key);
try {
JSONObject obj = new JSONObject(JSONString);
return obj;
} catch (Exception e) {
e.printStackTrace();
return null;
}
} // =======================================
// ============ JSONArray ���? ��д =============
// =======================================
/**
* ���� JSONArray���? �� ������
*
* @param key
* �����?key
* @param value
* �����?JSONArray���?
*/
public void put(String key, JSONArray value) {
put(key, value.toString());
} /**
* ���� JSONArray���? �� ������
*
* @param key
* �����?key
* @param value
* �����?JSONArray���?
* @param saveTime
* �����ʱ��?��λ����
*/
public void put(String key, JSONArray value, int saveTime) {
put(key, value.toString(), saveTime);
} /**
* ��ȡJSONArray���?
*
* @param key
* @return JSONArray���?
*/
public JSONArray getAsJSONArray(String key) {
String JSONString = getAsString(key);
try {
JSONArray obj = new JSONArray(JSONString);
return obj;
} catch (Exception e) {
e.printStackTrace();
return null;
}
} // =======================================
// ============== byte ���? ��д =============
// =======================================
/**
* ���� byte���? �� ������
*
* @param key
* �����?key
* @param value
* ��������
*/
public void put(String key, byte[] value) {
File file = mCache.newFile(key);
FileOutputStream out = null;
try {
out = new FileOutputStream(file);
out.write(value);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
mCache.put(file);
}
} /**
* ���� byte���? �� ������
*
* @param key
* �����?key
* @param value
* ��������
* @param saveTime
* �����ʱ��?��λ����
*/
public void put(String key, byte[] value, int saveTime) {
put(key, Utils.newByteArrayWithDateInfo(saveTime, value));
} /**
* ��ȡ byte ���?
*
* @param key
* @return byte ���?
*/
public byte[] getAsBinary(String key) {
RandomAccessFile RAFile = null;
boolean removeFile = false;
try {
File file = mCache.get(key);
if (!file.exists())
return null;
RAFile = new RandomAccessFile(file, "r");
byte[] byteArray = new byte[(int) RAFile.length()];
RAFile.read(byteArray);
if (!Utils.isDue(byteArray)) {
return Utils.clearDateInfo(byteArray);
} else {
removeFile = true;
return null;
}
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
if (RAFile != null) {
try {
RAFile.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (removeFile)
remove(key);
}
} // =======================================
// ============= ���л� ���? ��д ===============
// =======================================
/**
* ���� Serializable���? �� ������
*
* @param key
* �����?key
* @param value
* �����?value
*/
public void put(String key, Serializable value) {
put(key, value, -1);
} /**
* ���� Serializable��ݵ�? ������
*
* @param key
* �����?key
* @param value
* �����?value
* @param saveTime
* �����ʱ��?��λ����
*/
public void put(String key, Serializable value, int saveTime) {
ByteArrayOutputStream baos = null;
ObjectOutputStream oos = null;
try {
baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
oos.writeObject(value);
byte[] data = baos.toByteArray();
if (saveTime != -1) {
put(key, data, saveTime);
} else {
put(key, data);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
oos.close();
} catch (IOException e) {
}
}
} /**
* ��ȡ Serializable���?
*
* @param key
* @return Serializable ���?
*/
public Object getAsObject(String key) {
byte[] data = getAsBinary(key);
if (data != null) {
ByteArrayInputStream bais = null;
ObjectInputStream ois = null;
try {
bais = new ByteArrayInputStream(data);
ois = new ObjectInputStream(bais);
Object reObject = ois.readObject();
return reObject;
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
try {
if (bais != null)
bais.close();
} catch (IOException e) {
e.printStackTrace();
}
try {
if (ois != null)
ois.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null; } // =======================================
// ============== bitmap ���? ��д =============
// =======================================
/**
* ���� bitmap �� ������
*
* @param key
* �����?key
* @param value
* �����?bitmap���?
*/
public void put(String key, Bitmap value) {
put(key, Utils.Bitmap2Bytes(value));
} /**
* ���� bitmap �� ������
*
* @param key
* �����?key
* @param value
* �����? bitmap ���?
* @param saveTime
* �����ʱ��?��λ����
*/
public void put(String key, Bitmap value, int saveTime) {
put(key, Utils.Bitmap2Bytes(value), saveTime);
} /**
* ��ȡ bitmap ���?
*
* @param key
* @return bitmap ���?
*/
public Bitmap getAsBitmap(String key) {
if (getAsBinary(key) == null) {
return null;
}
return Utils.Bytes2Bimap(getAsBinary(key));
} // =======================================
// ============= drawable ���? ��д =============
// =======================================
/**
* ���� drawable �� ������
*
* @param key
* �����?key
* @param value
* �����?drawable���?
*/
public void put(String key, Drawable value) {
put(key, Utils.drawable2Bitmap(value));
} /**
* ���� drawable �� ������
*
* @param key
* �����?key
* @param value
* �����? drawable ���?
* @param saveTime
* �����ʱ��?��λ����
*/
public void put(String key, Drawable value, int saveTime) {
put(key, Utils.drawable2Bitmap(value), saveTime);
} /**
* ��ȡ Drawable ���?
*
* @param key
* @return Drawable ���?
*/
public Drawable getAsDrawable(String key) {
if (getAsBinary(key) == null) {
return null;
}
return Utils.bitmap2Drawable(Utils.Bytes2Bimap(getAsBinary(key)));
} /**
* ��ȡ�����ļ�
*
* @param key
* @return value ������ļ�?
*/
public File file(String key) {
File f = mCache.newFile(key);
if (f.exists())
return f;
return null;
} /**
* �Ƴ�ij��key
*
* @param key
* @return �Ƿ��Ƴ�ɹ�?
*/
public boolean remove(String key) {
return mCache.remove(key);
} /**
* ����������
*/
public void clear() {
mCache.clear();
} /**
* @title ���������?
* @author �����michael�� www.yangfuhai.com
* @version 1.0
*/
public class ASimpleCacheUtilManager {
private final AtomicLong cacheSize;
private final AtomicInteger cacheCount;
private final long sizeLimit;
private final int countLimit;
private final Map<File, Long> lastUsageDates = Collections
.synchronizedMap(new HashMap<File, Long>());
protected File cacheDir; private ASimpleCacheUtilManager(File cacheDir, long sizeLimit, int countLimit) {
this.cacheDir = cacheDir;
this.sizeLimit = sizeLimit;
this.countLimit = countLimit;
cacheSize = new AtomicLong();
cacheCount = new AtomicInteger();
calculateCacheSizeAndCacheCount();
} /**
* ���� cacheSize��cacheCount
*/
private void calculateCacheSizeAndCacheCount() {
new Thread(new Runnable() {
@Override
public void run() {
int size = 0;
int count = 0;
File[] cachedFiles = cacheDir.listFiles();
if (cachedFiles != null) {
for (File cachedFile : cachedFiles) {
size += calculateSize(cachedFile);
count += 1;
lastUsageDates.put(cachedFile,
cachedFile.lastModified());
}
cacheSize.set(size);
cacheCount.set(count);
}
}
}).start();
} private void put(File file) {
int curCacheCount = cacheCount.get();
while (curCacheCount + 1 > countLimit) {
long freedSize = removeNext();
cacheSize.addAndGet(-freedSize); curCacheCount = cacheCount.addAndGet(-1);
}
cacheCount.addAndGet(1); long valueSize = calculateSize(file);
long curCacheSize = cacheSize.get();
while (curCacheSize + valueSize > sizeLimit) {
long freedSize = removeNext();
curCacheSize = cacheSize.addAndGet(-freedSize);
}
cacheSize.addAndGet(valueSize); Long currentTime = System.currentTimeMillis();
file.setLastModified(currentTime);
lastUsageDates.put(file, currentTime);
} private File get(String key) {
File file = newFile(key);
Long currentTime = System.currentTimeMillis();
file.setLastModified(currentTime);
lastUsageDates.put(file, currentTime); return file;
} private File newFile(String key) {
return new File(cacheDir, key.hashCode() + "");
} private boolean remove(String key) {
File image = get(key);
return image.delete();
} private void clear() {
lastUsageDates.clear();
cacheSize.set(0);
File[] files = cacheDir.listFiles();
if (files != null) {
for (File f : files) {
f.delete();
}
}
} /**
* �Ƴ�ɵ��ļ�?
*
* @return
*/
private long removeNext() {
if (lastUsageDates.isEmpty()) {
return 0;
} Long oldestUsage = null;
File mostLongUsedFile = null;
Set<Entry<File, Long>> entries = lastUsageDates.entrySet();
synchronized (lastUsageDates) {
for (Entry<File, Long> entry : entries) {
if (mostLongUsedFile == null) {
mostLongUsedFile = entry.getKey();
oldestUsage = entry.getValue();
} else {
Long lastValueUsage = entry.getValue();
if (lastValueUsage < oldestUsage) {
oldestUsage = lastValueUsage;
mostLongUsedFile = entry.getKey();
}
}
}
} long fileSize = calculateSize(mostLongUsedFile);
if (mostLongUsedFile.delete()) {
lastUsageDates.remove(mostLongUsedFile);
}
return fileSize;
} private long calculateSize(File file) {
return file.length();
}
} /**
* @title ʱ����㹤����?
* @author �����michael�� www.yangfuhai.com
* @version 1.0
*/
private static class Utils { /**
* �жϻ����?String����Ƿ���?
*
* @param str
* @return true�������� false����û�е���
*/
private static boolean isDue(String str) {
return isDue(str.getBytes());
} /**
* �жϻ����?byte����Ƿ���?
*
* @param data
* @return true�������� false����û�е���
*/
private static boolean isDue(byte[] data) {
String[] strs = getDateInfoFromDate(data);
if (strs != null && strs.length == 2) {
String saveTimeStr = strs[0];
while (saveTimeStr.startsWith("0")) {
saveTimeStr = saveTimeStr
.substring(1, saveTimeStr.length());
}
long saveTime = Long.valueOf(saveTimeStr);
long deleteAfter = Long.valueOf(strs[1]);
if (System.currentTimeMillis() > saveTime + deleteAfter * 1000) {
return true;
}
}
return false;
} private static String newStringWithDateInfo(int second, String strInfo) {
return createDateInfo(second) + strInfo;
} private static byte[] newByteArrayWithDateInfo(int second, byte[] data2) {
byte[] data1 = createDateInfo(second).getBytes();
byte[] retdata = new byte[data1.length + data2.length];
System.arraycopy(data1, 0, retdata, 0, data1.length);
System.arraycopy(data2, 0, retdata, data1.length, data2.length);
return retdata;
} private static String clearDateInfo(String strInfo) {
if (strInfo != null && hasDateInfo(strInfo.getBytes())) {
strInfo = strInfo.substring(strInfo.indexOf(mSeparator) + 1,
strInfo.length());
}
return strInfo;
} private static byte[] clearDateInfo(byte[] data) {
if (hasDateInfo(data)) {
return copyOfRange(data, indexOf(data, mSeparator) + 1,
data.length);
}
return data;
} private static boolean hasDateInfo(byte[] data) {
return data != null && data.length > 15 && data[13] == '-'
&& indexOf(data, mSeparator) > 14;
} private static String[] getDateInfoFromDate(byte[] data) {
if (hasDateInfo(data)) {
String saveDate = new String(copyOfRange(data, 0, 13));
String deleteAfter = new String(copyOfRange(data, 14,
indexOf(data, mSeparator)));
return new String[] { saveDate, deleteAfter };
}
return null;
} private static int indexOf(byte[] data, char c) {
for (int i = 0; i < data.length; i++) {
if (data[i] == c) {
return i;
}
}
return -1;
} private static byte[] copyOfRange(byte[] original, int from, int to) {
int newLength = to - from;
if (newLength < 0)
throw new IllegalArgumentException(from + " > " + to);
byte[] copy = new byte[newLength];
System.arraycopy(original, from, copy, 0,
Math.min(original.length - from, newLength));
return copy;
} private static final char mSeparator = ' '; private static String createDateInfo(int second) {
String currentTime = System.currentTimeMillis() + "";
while (currentTime.length() < 13) {
currentTime = "0" + currentTime;
}
return currentTime + "-" + second + mSeparator;
} /*
* Bitmap �� byte[]
*/
private static byte[] Bitmap2Bytes(Bitmap bm) {
if (bm == null) {
return null;
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, baos);
return baos.toByteArray();
} /*
* byte[] �� Bitmap
*/
private static Bitmap Bytes2Bimap(byte[] b) {
if (b.length == 0) {
return null;
}
return BitmapFactory.decodeByteArray(b, 0, b.length);
} /*
* Drawable �� Bitmap
*/
private static Bitmap drawable2Bitmap(Drawable drawable) {
if (drawable == null) {
return null;
}
// ȡ drawable �ij���
int w = drawable.getIntrinsicWidth();
int h = drawable.getIntrinsicHeight();
// ȡ drawable ����ɫ��ʽ
Bitmap.Config config = drawable.getOpacity() != PixelFormat.OPAQUE ? Bitmap.Config.ARGB_8888
: Bitmap.Config.RGB_565;
// ������Ӧ bitmap
Bitmap bitmap = Bitmap.createBitmap(w, h, config);
// ������Ӧ bitmap �Ļ���
Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, w, h);
// �� drawable ���ݻ���������
drawable.draw(canvas);
return bitmap;
} /*
* Bitmap �� Drawable
*/
@SuppressWarnings("deprecation")
private static Drawable bitmap2Drawable(Bitmap bm) {
if (bm == null) {
return null;
}
return new BitmapDrawable(bm);
}
}
}
public class ExecutorServiceUtil { private static ExecutorService executorService;
private final static Object obj = new Object();
private ExecutorServiceUtil(){} public static ExecutorService getExecutorServiceInstance(){
if (executorService == null) {
synchronized (obj) {
if (executorService == null) {
executorService = Executors.newCachedThreadPool();
}
}
}
return executorService;
}
}
public class TAsyncRestClientUtil { private static AsyncHttpClient client = new AsyncHttpClient(); public static void get(String url, RequestParams params,
AsyncHttpResponseHandler responseHandler) {
client.get(url, params, responseHandler);
} public static void post(String url, RequestParams params,
AsyncHttpResponseHandler responseHandler) {
client.post(url, params, responseHandler);
} }
Android之针对webview的缓存的更多相关文章
- Android之针对WebView的全屏播放
转载请标明转载处:http://bbs.csdn.net/topics/390839259 本人刚学android,菜鸟一个,第一次写帖子,最近因为项目要用webview加载html5的视频,开始不能 ...
- Android WebView的缓存方式分析
WebView的缓存可以分为(1)页面缓存和(2)数据缓存. 页面缓存是指当WebView加载一个网页时的html.JS.CSS等页面或者资源数据.这些缓存资源是由于浏览器的行为而产生,开发者只能通过 ...
- Android:你不知道的 WebView 使用漏洞
前言 如今非常多App里都内置了Web网页(Hyprid App),比方说非常多电商平台.淘宝.京东.聚划算等等.例如以下图 上述功能是由 Android的WebView 实现的.可是 WebView ...
- Android Glide数据更新及内存缓存、硬盘缓存清理
[转] 原文 Android Glide数据更新及内存缓存.硬盘缓存清理 Android的Glide在加载图片时候内部默 ...
- 王立平--WebView的缓存机制
WebView的缓存能够分为页面缓存和数据缓存. 1. 页面缓存是指载入一个网页时的html.JS.CSS等页面或者资源数据. 这些缓存资源是因为浏览器的行为而产生.开发人员仅仅能通过配置HTTP ...
- 安卓使用WebView清除缓存
原文:https://blog.csdn.net/liwei123liwei123/article/details/52624826 Android 清除WebView缓存 最近项目中需要用WebVi ...
- 腾讯技术分享:Android版手机QQ的缓存监控与优化实践
本文内容整理自公众号腾讯Bugly,感谢原作者的分享. 1.问题背景 对于Android应用来说,内存向来是比较重要的性能指标.内存占用过高,会影响应用的流畅度,甚至引发OOM,非常影响用户体验.因此 ...
- Android开发之WebView具体解释
概述: 一个显示网页的视图.这个类是你能够滚动自己的Web浏览器或在你的Activity中简单地显示一些在线内容的基础.它使用了WebKit渲染引擎来显示网页,包含向前和向后导航的方法(通过历史记录) ...
- Android OkHttp与物理存储介质缓存:DiskLruCache(2)
Android OkHttp与物理存储介质缓存:DiskLruCache(2) 本文在附录文章8,9的基础之上,把Android OkHttp与DiskLruCache相结合,综合此两项技术,实 ...
随机推荐
- 算法之DP
一般DP 都是有模板的,先初始化,然后找到不同状态下数值的关系,使得某个状态可用另一个状态由一个固定的方式转移而来,列出状态转移方程,这就是DP: 例题 P1216 [USACO1.5]数字三角形 N ...
- application/json 四种常见的 POST 提交数据方式
四种常见的 POST 提交数据方式 HTTP/1.1 协议规定的 HTTP 请求方法有 OPTIONS.GET.HEAD.POST.PUT.DELETE.TRACE.CONNECT 这几种.其中 ...
- 什么是Less、typescript与webpack?
前端常用技术概述--Less.typescript与webpack 前言:讲起前端,我们就不能不讲CSS与Javascript,在这两种技术广泛应用的今天,他们的扩展也是层出不穷,css的扩展有Les ...
- 【LOJ】 #2308. 「APIO2017」商旅
题解 分数题可以想到分数规划,我们预处理出从i到j卖什么货物赚的最多,然后把每条边的边权改成"利润 - 效率 × 时间" 用spfa找正环即可 代码 #include <bi ...
- P2690 接苹果
P2690 接苹果f[i][j][k]表示i=1或2,表示j时刻cow在哪棵树下j表示时刻k表示转移了k次如果当前第1棵树落苹果f[1][t][left]=max(f[1][t-1][left],f[ ...
- HashMap几个需要注意的知识点
HashMap简介 HashMap 是java集合框架的一部分. key value都允许null值 (除了非同步和允许使用 null 之外,HashMap 类与 Hashtable 大致相同) 不保 ...
- ArduinoYun教程之ArduinoYun硬件介绍
ArduinoYun教程之ArduinoYun硬件介绍 ArduinoYun的电源插座 Arduino Yun有两排插座,这些插座可以按类型分为三类:电源.数字IO和模拟输入.电源部分主要集中在如图1 ...
- 8.7 正睿暑期集训营 Day4
目录 2018.8.7 正睿暑期集训营 Day4 A 世界杯(贪心) B 数组(线段树) C 淘汰赛 考试代码 A B C 2018.8.7 正睿暑期集训营 Day4 时间:5h(实际) 期望得分:. ...
- tesseract-ocr识别中文扫描图片实例讲解
当我浏览http://code.google.com/p/tesseract-ocr并下载了几个文件下来之后顿时感到一头雾水,不知该如何下手.网上看到有人在linux操作系统下的实现, 如: 利用开源 ...
- @Transactional导致AbstractRoutingDataSource动态数据源无法切换的解决办法
上午花了大半天排查一个多数据源主从切换的问题,记录一下: 背景: 项目的数据库采用了读写分离多数据源,采用AOP进行拦截,利用ThreadLocal及AbstractRoutingDataSource ...