Show version info only once on application start i

2020-03-07 06:39发布

I´d 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 ?

3条回答
甜甜的少女心
2楼-- · 2020-03-07 06:47

with a boolean variable stored somewhere : preferences, DB, SD card, ..

查看更多
小情绪 Triste *
3楼-- · 2020-03-07 06:49

A number of solutions are documented here:

What is SharedPreferences in Android?

查看更多
该账号已被封号
4楼-- · 2020-03-07 06:56

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
        }
查看更多
登录 后发表回答