Android开发中用到的缓存处理

来源:互联网 发布:ac1200双频路由器端口 编辑:程序博客网 时间:2024/05/17 22:16

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()方法中做顺序处理就可以了。

1 0
原创粉丝点击