This project is maintained by roaa1298

If the user presses Back repeatedly, each activity in the stack is popped off to show the one before it, until the user returns to the Home screen, The task is no longer active after all actions have been removed from the stack.
——–

## Android SharedPreferences
Here is an Example of how we can store the data in the shared preference in the onpause() When the user closes the application to save the data, and get the data again in the onResume() Because this is what will be called when the app opens again.
import androidx.appcompat.app.AppCompatActivity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity {
private EditText name, age;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = findViewById(R.id.edit1);
age = findViewById(R.id.edit2);
}
// Fetch the stored data in onResume()
// Because this is what will be called
// when the app opens again
@Override
protected void onResume() {
super.onResume();
// Fetching the stored data
// from the SharedPreference
SharedPreferences sh = getSharedPreferences("MySharedPref", MODE_PRIVATE);
String s1 = sh.getString("name", "");
int a = sh.getInt("age", 0);
// Setting the fetched data
// in the EditTexts
name.setText(s1);
age.setText(String.valueOf(a));
}
// Store the data in the SharedPreference
// in the onPause() method
// When the user closes the application
// onPause() will be called
// and data will be stored
@Override
protected void onPause() {
super.onPause();
// Creating a shared pref object
// with a file name "MySharedPref"
// in private mode
SharedPreferences sharedPreferences = getSharedPreferences("MySharedPref", MODE_PRIVATE);
SharedPreferences.Editor myEdit = sharedPreferences.edit();
// write all the data entered by the user in SharedPreference and apply
myEdit.putString("name", name.getText().toString());
myEdit.putInt("age", Integer.parseInt(age.getText().toString()));
myEdit.apply();
}
}