Check if key exists in Shared Preferences

Every method for fetching values from SharedPreferences has default value which is returned in case the key does not exist

preferences = getSharedPreferences("text", 0);
String value = preferences.getString("unknown_key",null);
if (value == null) {
    // the key does not exist
} else {
    // handle the value
}

Try out

 SharedPreferences shf = getSharedPreferences("NAME_SharedPref", MODE_WORLD_READABLE);
    String strPref = shf.getString("SERVERIP", null);

    if(strPref != null) {
    // do some thing

    }

Try contains(String key) Accorting to the Javadocs,

Checks whether the preferences contains a preference. Returns true if the preference exists in the preferences, otherwise false.