Reputation: 17
I have a Registration Activity, which I want to be started only once when the app is started for the first time. If the registration is made, the second time when the app is started I want to go directly to the second Activity - FirstWindow.
Thank you in advance!
Upvotes: 1
Views: 5462
Reputation: 369
Use a zero activity to check what to launch next, onCreate:
SharedPreferences sp= getSharedPreferences("first_time", 0);
ActivityZero.this.finish();
if (sp.getBoolean("FirstTime", true))
mainIntent = new Intent(ActivityZero.this, TutorialActivity.class);
else
mIntent = new Intent(ActivityZero.this, MainActivity.class);
ActivityZero.this.startActivity(mIntent);
Upvotes: 0
Reputation: 11196
when the activity is started for the first time : save true value in shared pref and everytime the app launches check the shared pref if true go to next activity else show first activity (ur registration page)
1.Declare variables
SharedPreferences pref;
SharedPreferences.Editor editor;
2.in onCrete method
pref = getSharedPreferences("testapp", MODE_PRIVATE);
editor = pref.edit();
3.When user successfully registers (click on register button)
editor.putString("register","true");
editor.commit();
Then every time u can check by :
String getStatus=pref.getString("register", "nil");
if(getStatus.equals("true"))
redirect to next activity
else
show registration page again
Upvotes: 6
Reputation: 1860
Create an activity with Theme.NoDisplay and make it your launcher activity (set intent filter for launcher in the manifest). In the onCreate, check if the user has registered or not and launch the appropriate activity. You can store the status of the user (registered/unregistered) in a DB or in SharedPreferences.
Upvotes: 0