作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
您能帮我弄清楚如何制作它,以便我的应用程序在进入主菜单之前让用户选中“我同意”框吗?我需要它仅在用户第一次使用该应用程序时显示此屏幕。我是 android studio 的新手,所以任何帮助将不胜感激。
谢谢!
最佳答案
您可以轻松使用SharedPreferences来实现这一点。尝试做类似的事情:
final String PREF_NAME = "MyPref";
// getting saved preferences
SharedPreferences settings = getSharedPreferences(PREF_NAME, 0);
if (settings.getBoolean("my_first_time", true)) {
//the app is being launched for first time, do something
Log.d("Comments", "First time");
// first time task
runUserAgreements();
// record the fact that the app has been started at least once
settings.edit().putBoolean("my_first_time", false).commit();
}
然后声明一个名为 runUserAgreements()
的函数,并运行一个显示用户协议(protocol)和内容的 Activity 或对话框。
我建议将上面的代码放在扩展Application
的类中 检查首次运行通常不在默认 Activity 中:
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// CODE HERE
}
}
并且不要忘记调用 AndroidManifest.xml 中的类:
<application android:name=".MyApp"
android:label="@string/app_name"
.
.
...>
....
</application>
关于java - 如何为应用程序上的用户制作一次性 "I agree" Activity 屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30278898/
我是一名优秀的程序员,十分优秀!