I have an activity that i only want to run when the application is ran for the first time.
And never again. It is a facebook login activity. I only want to launch it once when the app is initially opened for the first time.
How do i go about doing this?
This is my code to bring the OnBoarding Activity for the first time. If it's not the first time then go directly to the Home Activity.
Declare Globally
First Screen OnCreate
Now Outside Oncreat Method
Declared in the globally
in your onCreate function past this code at first.
Past these two method outside of onCreate
I had done this without Shared Prefrence...as I know shared prefrence consumes some memory so I used public static boolean variable in global class....First I made Global Class Appconfig...and then I made boolean static variable like this :
then I used this public static boolean variable into my welcome Activity class. I am Using License agreement page. which I have to use only at once in my application then never display further whenever i run the application. so i had put condtion in welcome activity...if the welcome class run first time so the static boolean variable is false...
Now at Licesnce Activity class I made :
So whenever I run the Application the second activity "Main activity" run after Welcome activity not License Activity....
What I've generally done is add a check for a specific shared preference in the
Main Activity
: if that shared preference is missing then launch the single-run Activity, otherwise continue with the main activity . When you launch the single run Activity create the shared preference so it gets skipped next time.EDIT : In my
onResume
for the default Activity I do this:Basically I load the default shared preferences and look for the
previously_started
boolean preference. If it hasn't been set I set it and then launch the help file. I use this to automatically show the help the first time the app is installed.