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();
}
# 1 楼答案
您可以很容易地使用SharedPreferences来实现这一点。试着做一些类似的事情:
然后声明一个名为
runUserAgreements()
的函数并运行一个显示用户协议和内容的活动或对话框编辑:
我建议将上述代码放在扩展
Application
的类中 要检查默认活动中通常不包含的firstrun:不要忘记调用AndroidManifest中的类。xml:
# 2 楼答案
看看Google的iosched项目示例,特别是这个活动:Welcome Activity。我觉得它的UI设计也很不错