简体   繁体   English

共享的偏好设置-首次检查是否为空

[英]Shared Preferences - First time check if empty

I'm just working with SP's and trying to check when a button is clicked if it is the first time the user uses the app. 我只是与SP一起工作,并尝试检查是否是用户第一次使用该应用程序时单击了什么按钮。 Below code is what I've tried but it does not enter the if and bring me to the next intent. 下面的代码是我尝试过的内容,但没有输入if并将其带入下一个意图。

any ideas? 有任何想法吗?

Thanks 谢谢

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

    myPreferences = getSharedPreferences(SHARED_PREFS, 0);
}

public void loginBtn(View v)
    {
    EditText editText =(EditText) findViewById(R.id.editText1);
    EditText editText2 =(EditText) findViewById(R.id.usernameID);
    if(myPreferences.equals(0))
    {
        if(editText.getText().toString().equals(userName) && editText2.getText().toString().equals(password) )
                {
                Intent intent = new Intent(this,ChangePassword.class);
                startActivity(intent);
                }
    }
String  myPreferences = getSharedPreferences(SHARED_PREFS, 0);

如果条件

if(myPreferences.equalsIgnoreCase(0))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM