简体   繁体   中英

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.

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. Check the preference when the user starts the application, and if it returns true then show the middle screen.

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...

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM