您的位置:首页 > 移动开发 > Android开发

Android开发中用到的缓存处理

2015-11-09 10:01 405 查看
Android开发中用到的缓存处理

首先我们要想到在何时何地我们需要缓存处理,我这里所讲的是一个用户体验方面的做法,曾有这样一个需求:当手机处于断网状态的时候,打开我的APP,我可以看到上一次看到的数据,那我们会怎么处理这种事情呢?

看过几篇文章,用法各有不同,在这里我要讲到一个我自己常用的方法。总体思路就是,在我App联网下载刷新时,我会已表的形式存储在我App的getApplicationContext().getFilesDir().getAbsolutePath();获取路径,利用我自己的工具类,(我自己的工具类已经上传,请见我博客)HttpUtils(),mNotificationAndBannerHandler
= http.download(PublicUrl.URL_PREFIX
+ "wap.php?action=actlist&cat=" + mCat + "&version=" + mVersion
+ "&member_phone=" + mUserName, path + "/" + mCat
+ "notificationandbannerdownload.json", false, true,
new RequestCallBack<File>() {

@Override
public void onStart() {
}

@Override
public void onLoading(long total, long current,
boolean isUploading) {
}

@Override
public void onSuccess(ResponseInfo<File> responseInfo) {
isNotificationFinish = true;
String v = getJsonFromDir(mCat
+ "notificationandbannerdownload.json");
if (MainActivityNew.isJson(v)) {
parseNotificationAndBannerJson(v);
setNotificationAndBannerData();
if (isNotificationFinish == true
&& isArticleFinish == true) {
mRefreshBar.setVisibility(View.GONE);
} else {
mRefreshBar.setVisibility(View.VISIBLE);
}
String path = getApplicationContext().getFilesDir()
.getAbsolutePath();
saveText(v, path, mCat
+ "notificationandbanner.json");
}
}

这样 我们就可以在下载的同时拿到一张表。在onCreat()方法中做顺序处理就可以了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: