Why is my String to String comparison failing?

后端 未结 3 367
醉酒成梦
醉酒成梦 2020-12-11 16:09

I have an Android app where I want to check to see if an app name that is installed matches a string passed to the function containing this code. The code and example is bel

3条回答
  •  青春惊慌失措
    2020-12-11 16:59

    Use the String's equals() method instead of the == operator for comparing strings:

    info.activityInfo.applicationInfo.loadLabel( pm ).toString().equals(appName)
    

    In Java, one of the most common mistakes newcomers meet is using == to compare Strings. You have to remember, == compares the object references, not the content.

提交回复
热议问题