【问题标题】:android splash screen timer pluginandroid闪屏计时器插件
【发布时间】:2016-01-18 03:58:29
【问题描述】:

我是开发android应用程序的新手,我正在尝试检查会话是否已登录,如果用户已登录,则不应显示启动画面,但如果用户未登录,则应显示启动画面屏幕 3 秒。

但是启动画面一直在显示,所以我认为我在 If/Else 方面做错了,希望有人可以帮助我:)

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);
        }

    }
}

【问题讨论】:

  • 你可以换个角度想。在您检查他们的登录状态时,如果他们已登录,请显示/隐藏您想要的布局元素,这些元素会产生飞溅效果并保持您的处理程序不变。如果他们未登录,则启动流程中的下一个活动并finish() 当前活动以将其关闭。

标签: java android splash-screen


【解决方案1】:

我在这里自己修复了这段代码:

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);
    }
}
}

【讨论】:

    猜你喜欢
    • 2022-08-03
    • 1970-01-01
    • 1970-01-01
    • 2017-05-24
    • 2022-10-20
    • 2023-03-10
    • 2018-07-14
    • 2015-08-10
    • 1970-01-01
    相关资源
    最近更新 更多