【发布时间】:2012-01-08 18:12:31
【问题描述】:
我希望我的应用有一个活动来显示有关如何使用该应用的说明。但是,这个“说明”屏幕只能在安装后显示一次,你是怎么做到的?
【问题讨论】:
标签: android layout android-activity installation splash-screen
我希望我的应用有一个活动来显示有关如何使用该应用的说明。但是,这个“说明”屏幕只能在安装后显示一次,你是怎么做到的?
【问题讨论】:
标签: android layout android-activity installation splash-screen
您可以测试是否在您的应用程序SharedPreferences 中设置了特殊标志(我们称之为firstRun)。如果不是,这是第一次运行,因此请根据说明显示您的活动/弹出窗口/任何内容,然后在首选项中设置firstRun。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences settings = getSharedPreferences("prefs", 0);
boolean firstRun = settings.getBoolean("firstRun", true);
if ( firstRun )
{
// here run your first-time instructions, for example :
startActivityForResult(
new Intent(context, InstructionsActivity.class),
INSTRUCTIONS_CODE);
}
}
// when your InstructionsActivity ends, do not forget to set the firstRun boolean
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == INSTRUCTIONS_CODE) {
SharedPreferences settings = getSharedPreferences("prefs", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("firstRun", false);
editor.commit();
}
}
【讨论】:
editor.putBoolean("firstRun", false); 而不是editor.putBoolean("firstRun", true);
是的,您可以使用 SharedPreferences 解决此问题
SharedPreferences pref;
SharedPreferences.Editor editor;
pref = getSharedPreferences("firstrun", MODE_PRIVATE);
editor = pref.edit();
editor.putString("chkRegi","true");
editor.commit();
然后检查String chkRegi ture or false
【讨论】: