创建仅在安装应用程序时显示的演练页面

时间:2015-05-15 13:20:39

标签: android installation walkthrough

我正在开发一个移动设备,其中有关应用程序的演练页面只应在安装应用程序后出现。任何人都可以通过一个明确的例子帮助我解决这个问题。

1 个答案:

答案 0 :(得分:1)

在您的方法中添加以下代码:

SharedPreferences prefs = getSharedPreferences(PREFERENCES_NAME, MODE_PRIVATE);

// Default value returned by next line is true.
boolean firstLaunch = prefs.getBoolean("firstLaunch", true);
if (firstLaunch) {
  // Do whatever you want here. This will be called only the first time the app launches.

  // Then edit the SharedPreferences and put the value as false. Unless changed back to true, this if statement/loop will never be called again.
  prefs.edit().putBoolean("firstLaunch", false).apply();
}

注意:PREFERENCES_NAME只是一个字符串。它可以是任何东西。我建议您在所有应用中使用相同的PREFERENCES_NAME,以防您需要在其他地方访问SharedPreferences。

相关问题