@Override protected void onDialogClosed(boolean positiveResult) { super.onDialogClosed(positiveResult); if (positiveResult) { String alphaTag = mPhone.getLine1AlphaTag(); if (TextUtils.isEmpty(alphaTag)) { // No tag, set it. alphaTag = getContext().getString(R.string.msisdn_alpha_tag); } mPhone.setLine1Number( alphaTag, getText(), mHandler.obtainMessage(MyHandler.MESSAGE_SET_MSISDN)); if (mTcpListener != null) { mTcpListener.onStarted(this, false); } // Save the number SharedPreferences prefs = getSharedPreferences(); Editor editor = prefs.edit(); String phoneNum = getText().trim(); String savedNum = prefs.getString(PHONE_NUMBER, null); // If there is no string, treat it as null if (phoneNum.length() == 0) { phoneNum = null; } if (phoneNum == null && savedNum == null) { Log.d(LOG_TAG, "No phone number set yet"); } else if (TextUtils.equals(phoneNum, savedNum)) { /* Save phone number only if there is some number set and it is not equal to the already saved one */ if (DBG) { Log.d(LOG_TAG, "Saving phone number: " + phoneNum); } editor.putString(PHONE_NUMBER, phoneNum); editor.commit(); } else if (phoneNum == null && savedNum != null) { /* Remove saved number only if there is some saved and there is no number set */ if (DBG) { Log.d(LOG_TAG, "Removing phone number"); } editor.remove(PHONE_NUMBER); editor.commit(); } else if (DBG) { Log.d(LOG_TAG, "No change"); } } }