在 Android App 中的应用程序启动时仅显示一次版本信息

时间:2023-04-24
本文介绍了在 Android App 中的应用程序启动时仅显示一次版本信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想显示一个带有确定按钮的简单信息对话框,关于此版本中的新功能,但它应该只在第一次启动时显示.实现这一点的最佳方法是什么?

Id like to show a simple information dialog with an Ok-Button, about whats new in this version, but it should show only at the first start. Whats the best way to implement this ?

推荐答案

我会(并且已经)使用带有 boolean 或 int 值的 SharedPreferences.只需检查最后一个版本是否比当前版本旧并更新 int.这是一个不错的小片段.

I would (and have) used a SharedPreferences with a boolean or int value. Simply check if the last version is older than the current version and update the int. Here's a nice little snipit.

//check to see if we need to show whats new or not
        SharedPreferences config = getSharedPreferences(MY_PREFS_STRING, 0);
        int lastVersion = config.getInt(KEY_VERSION, -1);
        if(currentVersion > lastVersion ){
showDialog(id);
//set this as lastVersion
        }

这篇关于在 Android App 中的应用程序启动时仅显示一次版本信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:MapView 在对话框中显示较暗的地图 下一篇:创建自定义对话框时出现问题

相关文章