0

Im trying to compare the versionName of my android app located in the build.grade with the version that takes from a external database.

My script is this:

version.add(jsonarray_appdata.getJSONObject(i).getString("version"));
                        String versionName = BuildConfig.VERSION_NAME;
                        String str = version.toString();
                        versionName = "[" + versionName + "]";
                        if(versionName != str){
                            Intent intent2 = new Intent(getApplicationContext(),Update.class);
                            startActivity(intent2);
                            finish();
                        } else {
                            Thread myThread = new Thread() {
                                @Override
                                public void run() {
                                    try {
                                        sleep(3000);
                                        Intent intent = new Intent(getApplicationContext(),MainActivity.class);
                                        startActivity(intent);
                                        finish();
                                    } catch (InterruptedException e) {
                                        e.printStackTrace();
                                    }
                                }
                            };
                            myThread.start();
                        }

The versionName value is "[1.3]" and the str value is "[1.3]". So the values are the same but it never goes to the else {} condition.

I tried removing the [ ] of both, and not working.

There are no blank spaces in the values.

Any idea what is happening?

Thanks!

1 Answers1

0

You are trying to compare strings, and versionName != str is not how you do it, you are just comparing references.

Change

versionName != str

To

versionName.equalsIgnoreCase(str)
bakero98
  • 805
  • 7
  • 18