什么是跳过活动的最佳方式 [英] What's the best way to skip an Activity

查看:171
本文介绍了什么是跳过活动的最佳方式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发中,在他的仪表盘上的用户登录,直到他注销(我的意思是,如果应用程序被关闭并重新启动,他仍然保持登录)保持记录在一个应用程序。我使用共享preferences 来检查,如果用户在实际登录。

I'm developing an app in which a user logs in to his dashboard and stays logged in until he logs out (I mean if the app is closed and restarted, he still stays logged in). I'm using SharedPreferences to check if the user is actually logged in.

preference.java

public class Preference {

    Context context;
    SharedPreferences sharedPref;

    public Preference(Context context){
        this.context = context;
        sharedPref = context.getSharedPreferences("LoginState", 0);
    }

    public boolean getIsLoggedIn(){
        return sharedPref.getBoolean("State", false);
    }

    public void setIsLoggedIn(boolean state){
        SharedPreferences.Editor editor = sharedPref.edit();
        editor.putBoolean("State", state);
        editor.commit();
    }

}

我调用该函数的用户 setIsLoggedIn(真)时,在用户登录和 setIsLoggedIn(假)时注销。但如何检查和跳过LoginActivity如果用户已经登录?

I call the function setIsLoggedIn(true) when the user logs in and setIsLoggedIn(false) when the user logs out. But how to check and skip the LoginActivity if the user is already logged in?

推荐答案

将这种情况在闪屏

Preference pre = new Preference(SplashScreen.this);
    if(preference.getIsLoggedIn()){
    // move to Login Screen
    }else{
     // move to your mainscreen
    }

这篇关于什么是跳过活动的最佳方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆