Intents, Activities, and SharedPreferences
What is SharedPreferences?
It is a way to save relatively small collection of key-values, it is managed by the framework and can be private or shared.
Create or access preference.
-
getSharedPreferences(): We can use this if we need multiple shared preference files identified by name.
-
getPreferences(): We can use this if we need to use one shared preference file for the activity.
Example of getSharedPreferences:
Context context = getActivity();
SharedPreferences sharedPref = context.getSharedPreferences(
getString(R.string.preference_file_key), Context.MODE_PRIVATE);
Example of write shared preferences:
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPref.edit();
editor.putInt(getString(R.string.saved_high_score_key), newHighScore);
editor.apply();
Example of read from shared preferences:
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);
Tasks and Back Stack in Android:
What is task?
A task is a set of activities that needs to interact with when performing a certain job.
When starting a new activity in is adding to the stack works, and if you start another one then want to go back to the previoce one, you cane do that be back which will let the user get back to the previous task in the stack works.

Default behavior for activities and tasks:
- When starting new Activity the previous Activity is stopped, but the system retains its state, if we press back, the previous Activity restored.