I am learning Android but i am not much experienced with java.
I write these code to check if there is any data in
sharedPreferences
sharedPreferences.Editor
if (savedData != null)
savedData
if (!savedData.isEmpty()
isEmpty()
null
isEmpty()
if (savedData != null)
if (!savedData.isEmpty())
Log.d("isRunning : ", "True")
if
private String saveString = null;
private ListView listView;
private static List<String> listArray = new ArrayList<String>();
private SaveListInSharedPreferences saveListInSharedPreferences = new SaveListInSharedPreferences();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences settings = getPreferences(MODE_PRIVATE);
String savedData = settings.getString(saveString, null);
if (savedData != null){
listArray = saveListInSharedPreferences.getList(savedData);
Log.d("isRunning : ", "True" );
}
if (myString != null && !myString.isEmpty()) {
//
}
If this doesn't work then it isn't null. If it's not working then try setting it directly equal to null beforehand, and then figuring out why that function isn't returning null . As to why myString != null doesn't work by itself, here's a post that can explain it better than I could. Avoiding != null statements