本文介紹了在 Android App 中的應用程序啟動時僅顯示一次版本信息的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我想顯示一個帶有確定按鈕的簡單信息對話框,關于此版本中的新功能,但它應該只在第一次啟動時顯示.實現這一點的最佳方法是什么?
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 ?
推薦答案
我會(并且已經)使用帶有 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 中的應用程序啟動時僅顯示一次版本信息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!