首页 文章 精选 留言 我的

精选列表

搜索[android wear],共10000篇文章
优秀的个人博客,低调大师

[开源应用]-一个Android平台的 IM 应用

这是一个简单的 IM 应用,写这个应用的本意只是想练练手,暂且实现了私聊和群聊功能,后边再根据用户反馈情况再来更新吧~ 应用完全是以 MVVM 的思想来实现的,使用的是 Google 的 LiveData + ViewModel 框架,使用的后台服务是由腾讯云通信服务提供的 应用完全开源,觉得还不错的同学不如点击应用内的“赞赏支持”来赞助我喝杯咖啡? GitHub主页:Round Apk下载地址:Round QQ交流群:892434439

优秀的个人博客,低调大师

Android Studio 使用Intent实现页面的跳转(带参数)

不管是在APP,还是在网站中,页面之间的跳转都是很常见的,本文主要讲一下在APP中,如何通过Intent实现页面的跳转。 不带参数: 写在MainActivity页面的代码: 1 Intent intent = new Intent(); 2 intent.setClass(MainActivity.this, LoginActivity.class);//从MainActivity页面跳转至LoginActivity页面 3 this.startActivity(intent); 带参数: 写在SpendingActivity页面的代码: 1 Intent intent=new Intent(SpendingActivity.this,ExpenseProcesActivity.class);//从SpendingActivity页面跳转至ExpenseProcesActivity页面 2 intent.putExtra("strType", 0);//参数:name、value 3 SpendingActivity.this.startActivity(intent); 写在ExpenseProcesActivity接收页面的代码: 1 private int type = 0; 2 3 //接收传递过来的参数 4 final Intent intent = getIntent(); 5 type = intent.getIntExtra("strType", 0); 备注: 可传递的参数有多种类型,在接收参数的时候,也要根据传入类型,选用对应的接收函数 传递参数的类型,Eg: 对应的接收函数,Eg: 如果您看了本篇博客,觉得对您有所收获,请点击右下角的 [推荐] 如果您想转载本博客,请注明出处 如果您对本文有意见或者建议,欢迎留言 感谢您的阅读,请关注我的后续博客

优秀的个人博客,低调大师

Android Studio 点击两次返回键,退出APP

该功能的实现没有特别复杂,主要在onKeyDown()事件中实现,直接上代码,如下: 1 //第一次点击事件发生的时间 2 private long mExitTime; 3 4 /** 5 * 点击两次返回退出app 6 */ 7 @Override 8 public boolean onKeyDown(int keyCode, KeyEvent event) { 9 if (keyCode == KeyEvent.KEYCODE_BACK) { 10 if ((System.currentTimeMillis() - mExitTime) > 2000) { 11 Object mHelperUtils; 12 Toast.makeText(this, "再按一次退出APP", Toast.LENGTH_SHORT).show(); 13 //System.currentTimeMillis()系统当前时间 14 mExitTime = System.currentTimeMillis(); 15 } else { 16 finish(); 17 } 18 return true; 19 } 20 return super.onKeyDown(keyCode, event); 21 } 如果您看了本篇博客,觉得对您有所收获,请点击右下角的 [推荐] 如果您想转载本博客,请注明出处 如果您对本文有意见或者建议,欢迎留言 感谢您的阅读,请关注我的后续博客

优秀的个人博客,低调大师

4-SII--☆Android缓存文件(带有效时长)封装

零、前言 [1]把我的缓存文件工具改写成了策略模式,感觉还不错。 [2]以前静态方法调用,很方便,但看着就是不爽,代码真的太冗余了。 [3]突然灵光一闪,"少年,看你骨骼惊奇,策略模式了解一下吗。"便有此文。 [4]如果不了解SharedPreferences,可以先看这篇:1-SII--SharedPreferences完美封装 缓存策略类图 缓存策略.png 一、使用: //新建缓存对象 CacheWorker innerCache = new CacheWorker(new InnerFileStrategy(this)); //设置缓存 innerCache.setCache("toly", "hehe", 10); //获取缓存 String value = innerCache.getCache("toly"); //SD卡缓存 CacheWorker sdCache = new CacheWorker(new SDFileStrategy()); sdCache.setCache("toly", "hehe2", 10); String sdCach = sdCache.getCache("toly"); //SharedPreferences CacheWorker spCache = new CacheWorker(new SPStrategy(this)); spCache.setCache("toly1994.com", "{name:toly}", 10); String spValue = spCache.getCache("toly1994.com"); 缓存.png 二、附录:各类及实现 /** * 作者:张风捷特烈<br/> * 时间:2018/8/26 0026:6:20<br/> * 邮箱:1981462002@qq.com<br/> * 说明:缓存策略接口 */ public interface CacheStrategy { /** * 存储缓存 * @param key 文件名 * @param value 文件内容 * @param time 有效时间 单位:小时 */ void setCache(String key, String value,long time); /** * 获取缓存 * @param key 文件名 * @return 文件内容 */ String getCache(String key); } /** * 作者:张风捷特烈<br/> * 时间:2018/8/26 0026:6:38<br/> * 邮箱:1981462002@qq.com<br/> * 说明:文件缓存基类 */ public abstract class BaseFileStrategy implements CacheStrategy { /** * 缓存文件的文件夹名称 */ private String mDirName; /** * 构造函数 * @param dirName 缓存文件的文件夹名称 */ public BaseFileStrategy(String dirName) { mDirName = dirName; } @Override public void setCache(String key, String value, long time) { // 以url为文件名, 以json为文件内容,保存在本地 // 生成缓存文件 File cacheFile = new File(mDirName + File.separator + Md5Util.getMD5(key)); FileWriter writer = null; try { if (!cacheFile.exists()) { cacheFile.getParentFile().mkdirs(); cacheFile.createNewFile(); } writer = new FileWriter(cacheFile); // 缓存失效的截止时间 long deadline = System.currentTimeMillis() + time * 60 * 60 * 1000;//有效期 writer.write(deadline + "\n");// 在第一行写入缓存时间, 换行 writer.write(value);// 写入文件 writer.flush(); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.close(writer); } } @Override public String getCache(String key) { // 生成缓存文件 File cacheFile = new File(mDirName + File.separator + Md5Util.getMD5(key)); // 判断缓存是否存在 if (cacheFile.exists()) { // 判断缓存是否有效 BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(cacheFile)); String deadline = reader.readLine();// 读取第一行的有效期 long deadTime = Long.parseLong(deadline); if (System.currentTimeMillis() < deadTime) {// 当前时间小于截止时间, // 说明缓存有效 // 缓存有效 StringBuilder sb = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { sb.append(line); } return sb.toString(); } else { setCache(key, "", 0);//缓存过期清空 } } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.close(reader); } } return null; } } /** * 作者:张风捷特烈<br/> * 时间:2018/8/26 0026:6:28<br/> * 邮箱:1981462002@qq.com<br/> * 说明:以文件保存缓存 到本包 <br/> */ public class InnerFileStrategy extends BaseFileStrategy { public InnerFileStrategy(Context context) { super(context.getCacheDir().getPath()); } } /** * 作者:张风捷特烈<br/> * 时间:2018/8/26 0026:6:28<br/> * 邮箱:1981462002@qq.com<br/> * 说明:以文件保存缓存 到SD卡cacheData目录 <br/> */ public class SDFileStrategy extends BaseFileStrategy { public SDFileStrategy() { super(Environment.getExternalStorageDirectory() +"/cacheData"); } } /** * 作者:张风捷特烈<br/> * 时间:2018/8/26 0026:8:03<br/> * 邮箱:1981462002@qq.com<br/> * 说明:SharedPreferences缓存 */ public class SPStrategy implements CacheStrategy { private Context mContext; public SPStrategy(Context context) { mContext = context; } @Override public void setCache(String key, String value, long time) { SpUtils<String> spString= new SpUtils<>(mContext); spString.put(key, value); SpUtils<Long> spLong = new SpUtils<>(mContext); spLong.put("LiftTime", System.currentTimeMillis() + time * 60 * 60 * 1000); } @Override public String getCache(String key) { SpUtils<Long> spLong = new SpUtils<>(mContext); Long liftTime = spLong.get("LiftTime", 0L); if (System.currentTimeMillis() < liftTime) {// 当前时间小于截止时间, SpUtils<String> spString= new SpUtils<>(mContext); return spString.get(key, ""); }else { setCache(key, "", 0);//缓存过期清空 } return null; } } /** * 作者:张风捷特烈<br/> * 时间:2018/8/26 0026:6:23<br/> * 邮箱:1981462002@qq.com<br/> * 说明:缓存工作类 */ public class CacheWorker { /** * 缓存策略 */ private CacheStrategy mCacheStrategy; /** * 无参构造 */ public CacheWorker() { } /** * 一参构造 * @param cacheStrategy 缓存策略 */ public CacheWorker(CacheStrategy cacheStrategy) { mCacheStrategy = cacheStrategy; } /** * 存储缓存 * @param key 文件名 * @param value 文件内容 * @param time 有效时间 单位:小时 */ public void setCache(String key, String value, long time) { mCacheStrategy.setCache(key, value, time); } /** * 获取缓存 * @param key 文件名 * @return 文件内容 */ public String getCache(String key) { return mCacheStrategy.getCache(key); } /** * 设置缓存策略 * @param cacheStrategy 缓存策略 */ public void setCacheStrategy(CacheStrategy cacheStrategy) { mCacheStrategy = cacheStrategy; } } 后记、 1.声明: [1]本文由张风捷特烈原创,转载请注明 [2]欢迎广大编程爱好者共同交流 [3]个人能力有限,如有不正之处欢迎大家批评指证,必定虚心改正 [4]你的喜欢与支持将是我最大的动力 2.连接传送门: 更多安卓技术欢迎访问:安卓技术栈 我的github地址:欢迎star 简书首发,腾讯云+社区同步更新张风捷特烈个人网站,编程笔记请访问:http://www.toly1994.com 3.联系我 QQ:1981462002 邮箱:1981462002@qq.com 微信:zdl1994328 4.欢迎关注我的微信公众号,最新精彩文章,及时送达: 公众号.jpg

资源下载

更多资源
优质分享App

优质分享App

近一个月的开发和优化,本站点的第一个app全新上线。该app采用极致压缩,本体才4.36MB。系统里面做了大量数据访问、缓存优化。方便用户在手机上查看文章。后续会推出HarmonyOS的适配版本。

Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码