1

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

4

1 回答 1

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。

于 2015-05-15T13:33:57.480 回答