Android的检查用户登录之前,其他人开始登录活动 [英] Android check user logged in before, else start login activity

查看:126
本文介绍了Android的检查用户登录之前,其他人开始登录活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想登录活动当用户启动应用程序,但还没有登录过启动。如果成功登录已经完成之前,应用程序将跳过登录页面,并移动到MainMenu.java。 我现在拥有的是:

I want the login activity to start when the user starts the app but has not logged in before. If a successful login has been completed before, the app will skip the login page and move to MainMenu.java. What I have now is:

    public class Login extends Activity implements OnClickListener, TaskCompleteCallback{

     first_time_check();

...
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.configure);

    ...}

private boolean first_time_check() {    
    String first = mPreferences.getString("first", null);
        if((first == null)){
            Intent i = new Intent(Login.this, MainMenu.class);
             startActivity(i);
        }
        return false;
    }

...
        SharedPreferences.Editor editor = mPreferences.edit();
        editor.putString("first", value);
    ...

        editor.commit();        

        // Close the activity
        Intent i = new Intent(Login.this, MainMenu.class);
         startActivity(i);
    }           

但我得到的功能界别。是什么问题我是如何实现共享preferences?

But I get FCs'. Is something wrong with how I implemented SharedPreferences?

推荐答案

您code只是从未调用 first_time_check(),从而自动前进的情况下老用户不能正常工作。

Your code just never calls that first_time_check(), thus the automatic forward in case of a returning user does not work.

您可以在的onCreate() DO

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

    first_time_check();

    setContentView(R.layout.configure);

    ...}

因此​​,对于新用户, first_time_check()将他转交到登录页面,否则 当前的布局将被显示,他可以继续在此页上。

So for a new user, first_time_check() would forward him to the login page, otherwise the current layout would be shown and he could continue on this page.

这篇关于Android的检查用户登录之前,其他人开始登录活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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