[英]Check if first-time user of my App in Android
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 (ie 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手机开发我的应用程序。
You can eg use a sharedPreference-object to store a boolean value that tells you if this is the first time the user opens the application. 例如,您可以使用sharedPreference-object来存储一个布尔值,该值告诉您这是否是用户第一次打开应用程序。 Check the preference when the user starts the application, and if it returns true then show the middle screen. 用户启动应用程序时检查首选项,如果返回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击败它...
Persist a flag in preferences and check it on startup. 在首选项中保留一个标志并在启动时检查它。 Change it's state after the splash is shown once. 在一次显示启动后更改它的状态。
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. 因此,您将检查此文件是否存在,如果它存在,那么您将不会显示第二个活动,并且只显示主要活动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.