java 检查我的应用程序是否是 Android 中的第一次用户

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2608210/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 22:00:40  来源:igfitidea点击:

Check if first-time user of my App in Android

javaandroid

提问by Praveen

In my App, first it shows a splash screen. After that another activity, then my main activity must be shown. This is my design plan. The second activity (i.e before main activity) must be shown for the first-time user of the app. If he/she closes the app, splash screen will redirect to main activity automatically. How do I do this? Any ideas? I am developing my app for Android phones.

在我的应用程序中,它首先显示一个启动画面。在另一个活动之后,必须显示我的主要活动。这是我的设计计划。必须为应用程序的首次用户显示第二个活动(即在主要活动之前)。如果他/她关闭应用程序,启动画面将自动重定向到主要活动。我该怎么做呢?有任何想法吗?我正在为 Android 手机开发我的应用程序。

回答by aspartame

You can e.g. use a sharedPreference-object to store a boolean value that tells you if this is the first time the user opens the application. Check the preference when the user starts the application, and if it returns true then show the middle screen.

例如,您可以使用 sharedPreference 对象来存储一个布尔值,该值告诉您这是否是用户第一次打开应用程序。在用户启动应用程序时检查首选项,如果返回 true,则显示中间屏幕。

private SharedPreferences mPreferences;
....
boolean firstTime = mPreferences.getBoolean("firstTime", true);
if (firstTime) { 
    SharedPreferences.Editor editor = mPreferences.edit();
    editor.putBoolean("firstTime", false);
    editor.commit();
    showMiddleActivity();
}

Something like that.

类似的东西。

Edit: Beaten to it by jqpubliq...

编辑:被 jqpubliq 打败了...

回答by jqpubliq

Persist a flag in preferencesand check it on startup. Change it's state after the splash is shown once.

首选项中保留一个标志并在启动时检查它。在飞溅显示一次后改变它的状态。

回答by Robby Pond

You'd need to save data somewhere, in your case it might be easiest to just write out an empty file after the first run of the app. So you would check for the existence of this file and if it was there then you wouldn't show the second activity, and would just show the main activity.

您需要将数据保存在某处,在您的情况下,在第一次运行应用程序后写出一个空文件可能是最简单的。因此,您将检查此文件是否存在,如果存在,则不会显示第二个活动,而只会显示主要活动。