我的if语句不工作 [英] My if statement doesn't work
本文介绍了我的if语句不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写在的Android
服务应用程序。在此应用中,我从主要业务使用 onStartCommand
事件接收命令。在如果
块检查变量。正如你可以在图片中(调试模式)看到,该值是开始,但如果
语句不起作用,并会重定向到否则
。为什么?
I am writing a service application in Android
. In this application, I am receiving commands from Main activity using onStartCommand
event. The IF
block is checking a variable. As you can see in the picture(Debug mode), the value is "start" but the IF
statement doesn't work and will redirect to Else
. why?
推荐答案
尝试 .equals
将帮助你...
字符串不是在Java主数据类型
总是使用 .equals()当你有对象
和字符串为对象
==
仅供基本数据类型
和 ==
中的对象进行比较的字符串Refrences ...不是...值
==
is only for primitive data type
and ==
in object compare your String Refrences...not value...
if(ReceivedCommandFromUser.equals("start"))
{
}
这篇关于我的if语句不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文