【安卓】判断"全新安装初次打开、升级后初次打开、第二次打开",比如可用于判断是否应显示"引导页"、!
2014-07-13 14:51
381 查看
思路:
1.基于SharedPreferences,每次打开时,根据上次打开时记录的版本即可区分此次打开的情形。
StoredData.java:
1.Application.onCreate中调用StoredData.getThis().markOpenApp();即可。其他位置就可以根据getLaunchMode判断打开类型了。
1.基于SharedPreferences,每次打开时,根据上次打开时记录的版本即可区分此次打开的情形。
StoredData.java:
1.Application.onCreate中调用StoredData.getThis().markOpenApp();即可。其他位置就可以根据getLaunchMode判断打开类型了。
package com.example.test; import android.app.Application; import android.content.SharedPreferences; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.text.TextUtils; public class StoredData { public static final int LMODE_NEW_INSTALL = 1; // 启动-模式,首次安装-首次启动、覆盖安装-首次启动、已安装-二次启动 public static final int LMODE_UPDATE = 2; public static final int LMODE_AGAIN = 3; private boolean isOpenMarked = false; private int launchMode = LMODE_AGAIN; // 启动-模式 private static StoredData instance; private SharedPreferences share; // 一般信息 public static StoredData getThis() { if (instance == null) instance = new StoredData(); return instance; } // -------启动状态------------------------------------------------------------ // 标记-打开app,用于产生-是否首次打开 public void markOpenApp() { // 防止-重复调用 if (isOpenMarked) return; isOpenMarked = true; String lastVersion = share.getString("lastVersion", ""); String thisVersion = getAppVersion(); // 首次启动 if (TextUtils.isEmpty(lastVersion)) { launchMode = LMODE_NEW_INSTALL; share.edit().putString("lastVersion", thisVersion).commit(); } // 更新 else if (!thisVersion.equals(lastVersion)) { launchMode = LMODE_UPDATE; share.edit().putString("lastVersion", thisVersion).commit(); } // 二次启动(版本未变) else launchMode = LMODE_AGAIN; } public int getLaunchMode() { return launchMode; } // 首次打开,新安装、覆盖(版本号不同) public boolean isFirstOpen() { return launchMode != LMODE_AGAIN; } // ------------------------- // 软件-版本 public static String getAppVersion() { String versionName = ""; Application app = MyApplication.getThis(); try { PackageManager pkgMng = app.getPackageManager(); PackageInfo pkgInfo = pkgMng .getPackageInfo(app.getPackageName(), 0); versionName = pkgInfo.versionName; } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } return versionName; } }
相关文章推荐
- Android 判断是否要进入引导页(引导页只需在安装后的第一次显示,以后不会显示)
- 解决Installer重新安装补丁错误-"无法打开此修补程序包。请确认该修补程序包存在,并且您可以访问它,或者与应用程序供应商联系,以确认这是否是一个有效的 Windows Installer 修补程序包。"
- 打开资源文件时显示说没有安装这个ActiveX控件 "{648A5600-2C6E-101B-82B6-000000000014
- 打开资源文件时显示说没有安装这个ActiveX控件 "{648A5600-2C6E-101B-82B6-000000000014
- ios APP初次安装以及版本更新后,判断是否需要显示引导页
- VS2008打开资源文件时显示说没有安装这个ActiveX控件 "{648A5600-2C6E-101B-82B6-000000000014
- 对安卓在浏览器中判断是否有本地应用安装,并打开本地应用的总结
- 在添加/删除''Add or Remove Programs"中不显示安装的应用程序(Hide Add/Remove Panel Entry)
- 用 document.readyState == "complete" 判断页面是否加载完成。
- javascript,判断表单是否为空,onSubmit=" return chk()"
- VC 判断左右"Control"键是否被按下
- 关于无法显示该网页,弹出对话框显示"Internet Explorer无法打开Internet站点xxx,已终止操作"问题的解决方法
- 虚机搭配NLB负载平衡时碰到"没有接口可用于安装新的群集"的解决方案
- winform判断一个窗口是否打开并显示出来
- JavaScript判断远程图片是否存在,加载完成:onerror 属性- & jQuery实现(如果因为网络或图片的原因发生异常,则显示该图片)~
- Power Point 打开显示 "无法找到打印机 Microsoft XPS Document Writer"
- Inno 4000 Setup安装、卸载时判断是否程序正在运行,安装完成时自动打开网页的脚本
- 用 document.readyState == "complete" 判断页面是否加载完成。
- document.getElementById("radFs")对象为空,js判断对象是否存在?
- x&(x-1)的巧用:用于判断x是否为2的n次幂,计算二进制1的个数