gpt4 book ai didi

android - 检测 Android 应用程序何时首次运行

转载 作者:行者123 更新时间:2023-11-29 02:10:05 25 4
gpt4 key购买 nike

我需要在 Android 应用程序首次运行时检测 Android 设备 ID。我提到我不使用共享首选项或文件。如何检测应用程序的首次运行?

最佳答案

您只能在第一次使用该代码块进行操作

在 onCreate 中:

 SharedPreferences prefs =
PreferenceManager.getDefaultSharedPreferences(this);
if (prefs.getBoolean("first_time", true)) {
//do something for first time
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("first_time", false);
editor.commit();
}

关于android - 检测 Android 应用程序何时首次运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7991970/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com