简体   繁体   English

第一屏。 仅在首次启动时显示

[英]First Screen. Shown on first Launch, ONLY

I want that when the users install my application and launch it for the first time try areshown " features of the application " but then that screen can neverbe accessed by the user. 我希望当用户安装我的应用程序并首次启动它时,请尝试显示“应用程序的功能”,但是该屏幕永远无法被用户访问。 It should never display again on the same device,ever. 永远不要再在同一设备上显示它。 It's just like, Showing an Initial Screen on first launch and no initial screen on subsequent launches. 就像在第一次启动时显示初始屏幕,而在随后的启动中不显示初始屏幕一样。 Any idea or example as to how can that be done. 关于如何完成的任何想法或示例。

Use SharedPreferences to set a flag. 使用SharedPreferences设置一个标志。 Define a key, and in your onCreate() , check if it's set or not. 定义一个键,然后在onCreate()中检查它是否已设置。 If it's not, display the window and write the key to preferences. 如果不是,请显示窗口并将密钥写入首选项。

private static final String FIRST_LAUNCH = "first_launch";

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences();

//Assume true if the key does not yet exist
if (prefs.getBoolean(FIRST_LAUNCH, true)) {
    //Display window
} else {
    SharedPreferences.Editor edit = prefs.edit();
    edit.putBoolean(FIRST_LAUNCH, false);
    edit.commit();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM