This is not necessary. The preference change listener gets called automatically when the pref is changed (on the line above) and it toggles the switch. Does it not work on your phone?