The project that I'm working on right now currently has 3 screens. Registration page, Login page and Homepage. After you register, you are taken back to the login page then from the login page to the homepage. I can use intents to pass the username from the login page to the home page but I don't know how to pass the String value (user type) from the registration page to the homepage. It seems like the intent only works when you push the button, that's why I can pass the value from login page to homepage when I press the button that takes me to the homepage.
Asked
Active
Viewed 87 times
-1
-
you can use this library for easy data sharing: https://github.com/kostasdrakonakis/android_navigator – Kostas Drak Feb 25 '18 at 21:11
1 Answers
0
From the top of my head I recall two ways:
- On button Click, when starting new activity:
public void nextFormPage(View v) {
Intent form_conclusion = new Intent(this, YOURCLASS.class); //define which class to go next
form_conclusion.putExtra("TAG", value);//passes the values to the next activity
startActivity(form_conclusion); //start the new activity
finish();
}
- Use sharedpreferences to store the value, and read it when needed
Write
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt(getString(R.string.saved_high_score_key), newHighScore); editor.commit();
Read
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); int defaultValue = getResources().getInteger(R.integer.saved_high_score_default_key); int highScore = sharedPref.getInt(getString(R.string.saved_high_score_key), defaultValue);

Vasco Lopes
- 141
- 9