当前位置: 首页 > news >正文

广州网站建设丿新科送推广cf租号网站怎么做的

广州网站建设丿新科送推广,cf租号网站怎么做的,关键词的选取原则有,装潢设计专业学校前言1、每一种要缓存的数据都是有对应的versionCode#xff0c;通过versionCode请求网络获取是否需要更新2、提前将要缓存的数据放入assets文件夹中#xff0c;打包上线。缓存设计代码实现/*** Created by huangbo on 2017/6/19.** 主要是缓存的工具类** 缓存设计#xff1a…前言1、每一种要缓存的数据都是有对应的versionCode通过versionCode请求网络获取是否需要更新2、提前将要缓存的数据放入assets文件夹中打包上线。缓存设计代码实现/*** Created by huangbo on 2017/6/19.** 主要是缓存的工具类** 缓存设计* 0.从内存中读取数据 0.1 读取成功- 取出versionCode -3* 0.2 读取失败- 1** 1.从文件中读取数据1.1读取成成功- 取出versionCode -3* 1.2读取失败- 2* 2.从Assets中读取数据2.1读取成功- 取出versionCode -3* 2.2读取失败- versionCode0 -3** 3.用versionCode请求网络 3.1请求成功(有版本更新)将文件写入内存写入文件* 3.1 请求失败(没有版本更新)**/public class CacheData {public static CacheData cacheData;public static CacheData getInstance() {if (cacheData null) {cacheData new CacheData();}return cacheData;}String mFileName;public CacheData cacheName(String mFileName) {this.mFileName mFileName;return this;}ExecutorService cachedThreadPool;private CacheData() {cachedThreadPool Executors.newCachedThreadPool();}/*** 从assets 中读取文件** return cacheData 的Json串*/private String readDataFromAssets() {try {InputStream ips AppUtils.ApplicationContext.getAssets().open(mFileName);byte[] bytes new byte[ips.available()];ips.read(bytes);ips.close();return new String(bytes);} catch (IOException e) {e.printStackTrace();}return ;}public void readDataFromAssets(final Handler handler) {cachedThreadPool.execute(new Runnable() {Overridepublic void run() {String json readDataFromAssets();Message message handler.obtainMessage(1, json);handler.sendMessage(message);}});}public void readDataFromFile(final Handler handler) {cachedThreadPool.execute(new Runnable() {Overridepublic void run() {Message message handler.obtainMessage(1, readDataFromFile());handler.sendMessage(message);}});}/*** 将region 更新到指定文件里* param*/public void writeData2FileWithThread(final String Data) {cachedThreadPool.execute(new Runnable() {Overridepublic void run() {writeRegion2File(Data);}});}/*** return cacheData 的Json串*/private String readDataFromFile() {try {File file new File(AppUtils.getCacheDirectory(), mFileName);if (!file.exists()) {return null;}FileInputStream fis new FileInputStream(file);byte[] bytes new byte[fis.available()];fis.read(bytes);fis.close();return new String(bytes);} catch (IOException e) {e.printStackTrace();}return ;}private void writeData2File(String jsonData) {try {File cityFile new File(AppUtils.getCacheDirectory(), mFileName);if (!cityFile.exists()) {cityFile.createNewFile();}FileOutputStream fos new FileOutputStream(cityFile);fos.write(regionJsonData.getBytes(UTF-8));fos.close();} catch (IOException e) {e.printStackTrace();}}}使用方法/*** Created by huangbo on 2017/6/8.*/public class Region {public static Region region;public static Region getInstance() {if (region null) {region new Region();}return region;}ProvinceCityBean provinceCityBean;public int getVersion() {return provinceCityBean null ? 0 : provinceCityBean.getVersion();}public ProvinceCityBean getProvinceCityBean() {return provinceCityBean;}public void setProvinceCityBean(final String mRegionJson, final Handler handler) {if (TextUtils.isEmpty(mRegionJson)) {return;}cachedThreadPool.execute(new Runnable() {Overridepublic void run() {provinceCityBean GsonUtils.GsonToBean(mRegionJson, ProvinceCityBean.class);if (handler ! null) {handler.sendEmptyMessage(1);}}});}ExecutorService cachedThreadPool;CacheData cacheData;private Region() {cachedThreadPool Executors.newCachedThreadPool();cacheData CacheData.getInstance().cacheName(Const.REGION_JSON);}/*** 具体调用方法*/public void cacheRegion() {if (provinceCityBean null) {readRegionFromFile();} else {readRegionFromHttp();}}private void readRegionFromFile() {cacheData.readDataFromFile(new Handler() {Overridepublic void handleMessage(Message msg) {String jsonRegion (String) msg.obj;onReadRegionFromFileBack(jsonRegion);}});}/*** 从文件中读取数据若为null 继续从Asset中获取** param jsonRegion*/private void onReadRegionFromFileBack(String jsonRegion) {if (!TextUtils.isEmpty(jsonRegion)) {/*文件中读取成功 设置到Region中更新json 取出version请求网络判断是否为最新的版本 */setProvinceCityBean(jsonRegion, httpHandler);} else {/*文件中读取失败 从assets 中继续读取*/cacheData.readDataFromAssets(new Handler() {Overridepublic void handleMessage(Message msg) {String jsonRegion (String) msg.obj;onReadRegionFromAssetsBack(jsonRegion);}});}}private void onReadRegionFromAssetsBack(String jsonRegion) {if (!TextUtils.isEmpty(jsonRegion)) {/*从assets中读取成功 设置到Region中更新json*/setProvinceCityBean(jsonRegion, httpHandler);} else {readRegionFromHttp();}}private void readRegionFromHttp() {ReqRegion reqRegion new ReqRegion();reqRegion.sendRequest(false, new OnHttpResult() {Overridepublic void onHttpSuccess(String data) {setProvinceCityBean(data, null);cacheData.writeData2FileWithThread(data);}Overridepublic void onHttpFailure(String message) {}});}Handler httpHandler new Handler() {Overridepublic void handleMessage(Message msg) {super.handleMessage(msg);readRegionFromHttp();}};}Region.getInstance().cacheRegion();//实现缓存以上为个人经验希望能给大家一个参考也希望大家多多支持脚本之家。如有错误或未考虑完全的地方望不吝赐教。
http://www.zqtcl.cn/news/953036/

相关文章:

  • 最新网站建设哪家公司好wordpress 顶部图片
  • 有什么网站可以做一起作业公司简介优秀文案
  • 太仓住房和城乡建设局网站seo网页推广
  • 网络公司 网站源码网页源代码修改了影响别人吗
  • 网站后台是怎样制作的app开发公司排行榜做软件的公司
  • 有专门做网站的公司吗西安分类信息seo公司
  • 重庆璧山网站制作公司哪家专业商城网站建设 优帮云
  • 双语网站建设费用安徽省芜湖建设定额网站
  • 常州市城乡建设局网站wordpress 阿里云cdn
  • 福州制作网站设计哪里比较好百度网址大全官方网站
  • 一般做美食网站的产品需求我想做个网站
  • 成品网站制作公司应用公园是免费的吗
  • 做毕业网站的流程网站建设价格一览表
  • 企业服务网站开发做网站怎样建立服务器
  • 电子商务他们的代表网站360免费wifi官网
  • 网站后端开发软件cc域名做门户网站
  • 保定设计网站超云建站
  • 建筑工程网官网入口优化网站关键词排名软件
  • 企业网站功能怎么设计wordpress文章图片轮播
  • 网站后台登陆验证码不对阳江房产网楼市数据
  • 营销型网站建设遨龙仙居住房和城乡建设规划局网站
  • 中国做视频网站有哪些淘宝做详情页代码网站
  • 网站开发一般多钱在网站设计公司上班好吗
  • 餐饮连锁企业网站建设方案北京软件研发公司
  • 外国网站架构新闻稿
  • 营销网站建设企划案例友情链接怎么添加
  • seo网站搜索优化目前好的推广平台
  • 快速搭建网站页面黄页88网免费发布信息
  • 做网站能赚吗网址大全查询ip地址
  • html5网站正在建设中商城网站系统