After reading some statistics about my app I saw that it takes over one month to update 75% of my users. Since all updates are very important I’ve come up to make an in-app alert that tells users that there is an update pending.
There is a text file containing the actual app version (18), stored in a webserver which is gotten by the DownloadText() method. This number goes in isUpdatetxt and is extracted from non-displayable characters with .substring(1, 3). So basically, there’s only “18” left.
But there is my problem: isUpdatetxt == "18" returns false, when it’s not supposed to.
private class GetUpdate extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
Toast.makeText(getApplicationContext(), "Vérification de mise à jours", Toast.LENGTH_LONG).show();
}
@Override
protected void onPostExecute(Void result) {
/** For debug reference*/
Toast.makeText(getApplicationContext(), "*" + isUpdatetxt + "*" + " " + (isUpdatetxt.length()), Toast.LENGTH_LONG).show();
if(isUpdatetxt == "18"){
alertDialog.show();
}
}
@Override
protected Void doInBackground(Void... params) {
isUpdatetxt = DownloadText(updateURL);
isUpdatetxt = isUpdatetxt.substring(1, 3);
return null;
}
}
If you are comparing Strings in Java, you should be using .equals().
When you compare strings with == in Java, you compare the references.
So your if-statement will be something like: