private void setDweetingStatus(boolean enabled) { Log.i(TAG, "Setting dweet to " + enabled); SharedPreferences.Editor editor = getPreferences().edit(); String thingname = getPreferenceString(R.string.dweeting_thingname_key); if (thingname == null || thingname.equals("")) { thingname = DweetLib.getInstance(getContext()).getRandomThingName(); editor.putString(getString(R.string.dweeting_thingname_key), thingname); editor.putString(getString(R.string.dweeting_thingname_default), thingname); editor.apply(); } if(enabled) { if(mDweeter != null) { stopDweeting(); } try { mDweeter = new DweetSink(getContext(), thingname); } catch(Exception e) { Log.w(TAG, "Unable to add dweet sink", e); return; } getVehicleManager().addSink(mDweeter); } else { stopDweeting(); } }