Java – if you use the Boolean Android statement

I've encountered Boolean problems in if statements all day. Now I'm really bothering me! I've seen other Android threads here, and the solution doesn't seem to work

My code starts like this:

public class MainActivity extends Activity 
{
public static boolean isSignedIn = false;       

public final static String USERNAME_MESSAGE = "com.example.libnoise.MESSAGE";
Button btnSignIn;

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


    btnSignIn = (Button) findViewById(R.id.btnSignIn);
    Intent intent = getIntent();
    String message = intent.getStringExtra(PlayZone.USERNAME_MESSAGE); 

    if(isSignedIn == false))
    {
   btnSignIn.setText("SignIn");
    }
    else
    {       
         btnSignIn.setText(message);
    }        
}

Then I have an idea that it makes it different from other languages. I only need an "=" symbol, so I do this:

if(isSignedIn = false)
    {
   btnSignIn.setText("SignIn");
    }
    else
    {       
         btnSignIn.setText(message);
    }

This doesn't work. When I start looking for online, after finding the previous thread, change it to the following:

if("false".equals(isSignedIn))
    {
   btnSignIn.setText("SignIn");
    }
    else
    {       
         btnSignIn.setText(message);
    }

Now, it's not appropriate for me, but I hope it will work, but that's not the case

Because this is the mainactivity it loads first, but because I added all these, it will even load when I take out the if statement that works as expected before the application crashes

Any ideas?

Solution

I think you can use it simply

if(!isSignedIn)
{
  btnSignIn.setText("SignIn");
}
else
{       
  btnSignIn.setText(message);
}

The way you follow is also correct. I don't find any errors unless you use additional parentheses if (issignedin = = false) in the condition

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>