tags:

views:

204

answers:

3

hi all,

In my App, first it shows a splash screen. after that another activity, then my main activity must be show. this is my design plan. the second activity(i.e before main activity) must be show for the first time user of the app. if he/she closes the app.splash screen will redirect to main activity automatically. how to do this ? Any Idea? i am developing my app for android phones.

A: 

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.

BrennaSoft
+9  A: 

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

jqpubliq
+8  A: 

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.

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

aspartame
I would also make sure that the preferences name that you select is more unique in naming, using the usual "URI" format makes sure that other apps don't use the same "firstTime" preference. So something like "com.yoursite.yourapp.FirstTime", hopefully nobody else would name their preference the same as your site and app.
Adam
I'm pretty sure preferences are local to the application so there is no need to prefix them or anything.
alexanderblom