Hide activity on button click with shared preferences, android studio

How can I use shared preference in android studio to achieve this?

On my app, Splash Screen redirects to Activity A.

There is a button on Activity A, When this button on Activity A is clicked, next time when user opens app, Activity A will not show again, Activity B must open next.

The logic here is, Activity A is my welcome screen, after user clicks get started on this activity, I don’t want this Activity to open again. Activity B is my Main Activity

NB: I have checked all questions and answers on stackoverflow, they did not help, the ones available where showing activity only on first run and this not a duplicate question, any help provided is appreciated.


You can store boolean by shared preference to do that. Here your AcitivityA class.

public class ActivityA extends AppCompatActivity {

private SharedPreferences prefs;

protected void onCreate(Bundle savedInstanceState) {
    Button button = findViewById(R.id.button);

    try {
        prefs = PreferenceManager.getDefaultSharedPreferences(this);
        boolean firsttimeLoad = prefs.getBoolean("first_time_load", true);
        if (!firsttimeLoad) {
    } catch (Exception e) {

    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            SharedPreferences.Editor editor = prefs.edit();
            editor.putBoolean("first_time_load", false);


private void sendToB() {
    Intent mainIntent = new Intent(ActivityA.this, ActivityB.class);