0

i have my app's signup type page which is use for getting details of user and i have made it to run for one time only using sharedpreferences method but i got one problem that if user close that app during filling of details than that activity is not coming again.

setContentView(R.layout.register_data);
getSharedPreferences("PREFERENCE", MODE_PRIVATE)
boolean isFirstRun = getSharedPreferences("PREFERENCE",MODE_PRIVATE).getBoolean("isFirstRun", true);
 if (isFirstRun){
    startActivity(new Intent(MainActivity.this, RegisterDetail.class));
   .edit()
   .putBoolean("isFirstRun", false)
    .apply();

}

Jay Desai
  • 231
  • 1
  • 2
  • 12
  • Possible duplicate of [How to launch activity only once when app is opened for first time?](http://stackoverflow.com/questions/7238532/how-to-launch-activity-only-once-when-app-is-opened-for-first-time) – Yogesh Rathi Aug 04 '16 at 05:43
  • Add another boolean value to check whether the user has clicked Register button or the button you have. And in `onPause()` or `onStop()` method of the Registration activity check this boolean. If user hasn't clicked Register make your sharedpreferences boolean True again. – Rajith Shanika Aug 04 '16 at 05:57

1 Answers1

0

Check this link May be it is helpful to you

Some ref

 SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    boolean previouslyStarted = prefs.getBoolean(getString(R.string.pref_previously_started), false);
    if(!previouslyStarted) {
        SharedPreferences.Editor edit = prefs.edit();
        edit.putBoolean(getString(R.string.pref_previously_started), Boolean.TRUE);
        edit.commit();
        showHelp();
    }
Community
  • 1
  • 1
Yogesh Rathi
  • 6,331
  • 4
  • 51
  • 81