'how to make automatic multi user login SplasScreen Android Studio

I want to make automatic multi-user login in my application. In my code below, still using single user, when the login session is successful, it will immediately be carried over to user 1, even though I logged in using user 2 can you help me?

Splashcreen.java

sessionManager = new SessionManager(this);
        sessionManager.checkLogin2();
        sessionManager2 = new SessionManager2(this);
        sessionManager2.checkLogin3();


        if(!sessionManager.checkLogin2()){
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent intent = new Intent(welcome_activity.this, DashboardActivity.class);
                    startActivity(intent);
                    finish();
                    return;
                }
            }, 2000);
        }   if(!sessionManager2.checkLogin3()){
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Intent intent = new Intent(welcome_activity.this, DashboardActivityP.class);
                    startActivity(intent);
                    finish();
                    return;
                }
            }, 2000);
        }
        else {
            Intent intent = new Intent(welcome_activity.this, LoginActivity.class);
            startActivity(intent);
            finish();
        }

SessionManager.java

public boolean isLoggin(){
        return sharedPreferences.getBoolean(LOGIN, false);
    }
    public boolean checkLogin2(){
        return !this.isLoggin();
    }
    public void checkLogin(){

SessionManager2.java

public boolean isLoggin(){
        return sharedPreferences.getBoolean(LOGIN, false);
    }
    public boolean checkLogin3(){
        return !this.isLoggin();
    }
    public void checkLogin(){
}


Solution 1:[1]

Android provides Splash screens API

https://developer.android.com/guide/topics/ui/splash-screen

  1. Use windowSplashScreenBackground to fill the background with a specific single color:

<item name="android:windowSplashScreenBackground">@color/...</item>

  1. Use windowSplashScreenAnimatedIcon to replace an icon in the center of the starting window. If the object is animatable and drawable through AnimationDrawable and AnimatedVectorDrawable, you also need to set windowSplashScreenAnimationDuration to play the animation while showing the starting window.

<item name="android:windowSplashScreenAnimatedIcon">@drawable/...</item>

  1. Use windowSplashScreenAnimationDuration to indicate the duration of the splash screen icon animation. Setting this won't have any effect on the actual time during which the splash screen is shown, but you can retrieve it when customizing the splash screen exit animation using SplashScreenView#getIconAnimationDuration. See Keep the splash screen for longer periods in the following section for further details.

<item name="android:windowSplashScreenAnimationDuration">1000</item>

  1. Use windowSplashScreenIconBackgroundColor to set a background behind the splash screen icon. This is useful if there isn’t enough contrast between the window background and the icon.

<item name="android:windowSplashScreenIconBackgroundColor">@color/...</item>

  1. Optionally, you can use windowSplashScreenBrandingImage to set an image to be shown at the bottom of the splash screen. The design guidelines recommend against using a branding image.

<item name="android:windowSplashScreenBrandingImage">@drawable/...</item>

Keep the splash screen on-screen for longer periods :

//Create a new event for the activity.
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Set the layout for the content view.
        setContentView(R.layout.main_activity);
    
        // Set up an OnPreDrawListener to the root view.
        final View content = findViewById(android.R.id.content);
        content.getViewTreeObserver().addOnPreDrawListener(
                new ViewTreeObserver.OnPreDrawListener() {
                    @Override
                    public boolean onPreDraw() {
                        // Check if the initial data is ready.
                        if (mViewModel.isReady()) {
                            // The content is ready; start drawing.
                         content.getViewTreeObserver().removeOnPreDrawListener(this);
                            return true;
                        } else {
                            // The content is not ready; suspend.
                            return false;
                        }
                    }
                });
    }

Customize the animation for dismissing the splash screen

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // ...

    // Add a callback that's called when the splash screen is animating to
    // the app content.
    getSplashScreen().setOnExitAnimationListener(splashScreenView -> {
        final ObjectAnimator slideUp = ObjectAnimator.ofFloat(
                splashScreenView,
                View.TRANSLATION_Y,
                0f,
                -splashScreenView.getHeight()
        );
        slideUp.setInterpolator(new AnticipateInterpolator());
        slideUp.setDuration(200L);

        // Call SplashScreenView.remove at the end of your custom animation.
        slideUp.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                splashScreenView.remove();
            }
        });

        // Run your animation.
        slideUp.start();
    });
}

By the start of this callback, the animated vector drawable on the splash screen has begun. Depending on the duration of the app launch, the drawable might be in the middle of its animation. Use SplashScreenView.getIconAnimationStart to know when the animation started. You can calculate the remaining duration of the icon animation as follows:

    long remainingDuration;
    if (animationDuration != null && animationStart != null) {
        remainingDuration = animationDuration.minus(
                Duration.between(animationStart, Instant.now())
        ).toMillis();
        remainingDuration = Math.max(remainingDuration, 0L);
    } else {
        remainingDuration = 0L;
    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kishan Mevada