Search code examples
javaandroidandroid-studiobuttonandroid-activity

activity not displayed after the button is pressed, one-time activity with button


how After the "Splash screen" should go to the "about program" activity, which opens once, then click "I read" button, go to "Main Activity" and return should not open the "about program" at all. If you do not click on the button in the "about program" activity, the "about program" activity should open (until the button is pressed). if you have this code, please leave it. thank you.

NEW USER (NOT CLICKED BUTTON) SPLASH SCREEN > INFORMATION ACTIVITY | leave app, retry turn app | SPLASH SCREEN > INFORMATION ACTIVITY

NEWS USER (CLICKED BUTTON) SPLASH SCREEN > INFORMATION ACTIVITY > MAIN ACTIVITY | leave app, retry turn app | SPLASH SCREEN > MAIN ACTIVITY


Solution

  • You can hold a boolean value in shared preference . if it false navigate user to info activity . on button click change bool value to true. if true then navigate user to main activity.

    in Splash check for boolean value

    SharedPreferences sharedpreferences = getSharedPreferences("MyPref",Context.MODE_PRIVATE);
    
    boolean value= sharedpreferences .getBoolean('yourKey',false);
    
    if(!value){
    
    //navigate user to info activity
    
    }else{
    
    //navigate user to Main activity
    }   
    

    on read button click

    //.........make boolena value to true ............

    SharedPreferences sharedpreferences = getSharedPreferences("MyPref",Context.MODE_PRIVATE);
    SharedPreferences.Editor editor = sharedpreferences .edit();
    editor.putBoolean("yourKey", true);
    editor.apply();