androidpreferenceedittextpreference

Android: EditTextPreference dialog showing value from previous invocation


In my application I have a list of accounts in the settings screen. If you click on an account you go to a screen showing the account details. The account name is an EditTextPreference, if you click on it Android shows a dialog enabling you to change the name of the account.

The very first time this dialog is shown there is no value specified. The user enters the new name for the account and clicks OK and the account name is updated.

The problem is when I then view a different accounts details and click on its name to edit it, the dialog is showing the text from my previous rename. Why is this not showing no value or the current name of the account? Why is it reusing a value from a different account?

enter image description here


Solution

  • The problem was caused because shared preference name is "global". So when you open the preference for one account you are getting the value that was last set.

    The fix we have done is in our setting's screen's onCreate() we reset the account name preference to the name of the account the setting screen is for. Then when the edit name dialog is opened it has the correct account name.