Reputation: 351
Problems
I have used following code
Below code will not meet my requirement?
Any Help will be appreciated!!
Code in Registration Activity
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor=prefs.edit();
editor.putBoolean("registration", true);
editor.commit();
Code in Main Activity
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean regComplete =prefs.getBoolean("registration", false);
SharedPreferences.Editor editor =prefs.edit();
editor.putBoolean("registration", false);
editor.commit();
if(regComplete)
{
startActivity(new Intent(this, SecureXActivity.class));
} else
{
startActivity(new Intent(this, LoginActivity.class));
}
Upvotes: 2
Views: 108
Reputation: 24012
The Registration Activity should be like this:
public class RegistrationActivity extends Activity {
public static SharedPreferences pref;
public static final String PREFS_NAME = "MyPrefsFile";
public void onCreate(Bundle savedInstanceState) {
pref = getSharedPreferences(PREFS_NAME, 0);
boolean regComplete =prefs.getBoolean("registration", false);
if(regComplete){
//go to main class
}else{
//stay in the registration class
}
}
}
and the Main class should be:
public class MainActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
RegistrationActivity.pref = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putBoolean("registration", true);
// Commit the edits!
editor.commit();
}
}
Upvotes: 1
Reputation: 109237
Just put your Registration code in SecureXActivity.class
and Check for the Registration before setContentView()
, if its not done then start LoginActivity
.class
And in LoginActivity.class
after registration complete put these code,
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor=prefs.edit();
editor.putBoolean("registration", true);
editor.commit();
If you use this approach then I think you don't need Main Activity class
..
And keep in mind this all thing done at time of your application's first run not at the time of installation.
Upvotes: 3