-1

In my android application I am saving the last order did in Sharedpreference. When the user check for last order I am calling Sharedprefernce and showing it. That is working perfectly. But if nothing is saved in shared preference app is crashing. So I would like to check whther sharedpreference has any values saved or not first.

String lastOrder = sharedPreferences.getString("orderNO", "");

roshanpeter
  • 1,334
  • 3
  • 13
  • 32

1 Answers1

0

you just need to check isEmpty of you sharedPreference value before setting it

   String lastOrder = sharedPreferences.getString("orderNO", "");

   if (!lastOrder.equals("")){
        orderField.setText(lastOrder);
    }
saqib kafeel
  • 296
  • 3
  • 8