当用户安装我的应用程序时如何显示启动画面。我不想每次用户打开它时都显示启动屏幕,但仅当用户将其安装在手机上并第一次打开它时才显示。如何实现这一目标?
最佳答案
在每次启动应用程序时显示的主 Activity 中,尝试以下逻辑。
SharedPreferences mPrefs;
final String splashScreenPref= "SplashScreenShown";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
Boolean splashScreenShown= mPrefs.getBoolean(splashScreenPref, false);
if (!splashScreenShown) {
Intent intent=new Intent(MainActivity.this,SplashScreenActivity.class);
startActivity(intent);
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(splashScreenShown, true);
editor.commit();
finish();
}
}
关于android - 如何在App上显示一次启动画面?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38673308/