Skip to content
Advertisement

android splash screen timer plugin

I am new into developing android app, and I am trying to check if session is logged in, If the user is loggedin, It should not show the splash screen, but it the user is not loggedin, it should show the splash screen for 3 seconds. (Using code from http://web.archive.org/web/20130712051340/http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/)

But the Splash screen is showing all the time, so I think I done it wrong with the If/Else thing, hope someone can help me with that 🙂

public class SplashScreen extends Activity {

    // Splash screen timer
    private static int SPLASH_TIME_OUT = 3000;
    private SessionManager session;

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

        // Session manager
        session = new SessionManager(getApplicationContext());

        // Check if user is already logged in or not
        if (session.isLoggedIn()) {
            // User is already logged in. Take him to main activity
            new Handler().postDelayed(new Runnable() {

            /*
             * Showing splash screen with a timer. This will be useful when you
             * want to show case your app logo / company
             */

                @Override
                public void run() {
                    // This method will be executed once the timer is over
                    // Start your app login activity
                    Intent i = new Intent(SplashScreen.this, LoginActivity.class);
                    startActivity(i);

                    // close this activity
                    finish();
                }
            }, SPLASH_TIME_OUT); } else {
            setContentView(R.layout.splash_screen);
        }

    }
}

Advertisement

Answer

I Fixed it my self this this code here:

public class SplashScreen extends Activity {

// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;
private SessionManager session;

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

    // Session manager
    session = new SessionManager(getApplicationContext());

    // Check if user is already logged in or not
    if (session.isLoggedIn()) {
        // User is already logged in. Take him to main activity

        Intent i = new Intent(SplashScreen.this, MainActivity.class);
        startActivity(i);

        // close this activity
        finish();

    } else {

        setContentView(R.layout.splash_screen);
        new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

            @Override
            public void run() {

                Intent i = new Intent(SplashScreen.this, LoginActivity.class);
                startActivity(i);

                // close this activity
                finish();
            }
        }, SPLASH_TIME_OUT);
    }
}
}
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement