Очень странная ситуация, которую я заметил ...
private void saveFavArticles() {
SharedPreferences pref = getSharedPreferences(PUT_FAVORITE_CRNT_ARTICLE_KEY, Context.MODE_PRIVATE);
String currentFavList = pref.getString(PUT_FAVORITE_CRNT_ARTICLE_KEY, "");
SharedPreferences.Editor editor;
ArrayList<Article> articles = new ArrayList<>();
//if we have favorite articles
if(currentFavList != "") {
Type type = new TypeToken<List<Article>>(){}.getType();
articles = new Gson().fromJson(currentFavList, type);
//It returns true if the specified element is found in the list else it gives false.
if(articles.contains(currentArticle))
Toast.makeText(this, "this article exists into favorite list", Toast.LENGTH_SHORT).show();
else{
articles.add(currentArticle);
Toast.makeText(this, "current article added to favorites", Toast.LENGTH_SHORT).show();
}
editor = pref.edit();
editor.putString(DetailsActivity.PUT_FAVORITE_CRNT_ARTICLE_KEY, new Gson().toJson(articles));
}else {
editor = pref.edit();
articles.add(currentArticle);
editor.putString(DetailsActivity.PUT_FAVORITE_CRNT_ARTICLE_KEY, new Gson().toJson(articles));
Toast.makeText(this, "current article added to favorites", Toast.LENGTH_SHORT).show();
}
editor.commit();
}
Я отлаживаю это утверждение ... проблема в том, что даже когда мой массив содержит currentArticle, он всегда говорит, что нет.
какая-либо помощь?