I am overriding the onCreateDialog and onPrepareDialog methods or the Dialog class.
I have followed the example from Reto Meier\'s Professional Android Application Devel
I don't have Reto's book so I can't check the code, but if there is a mistake in the book you can contact him easily on Twitter to discuss it: http://twitter.com/retomeier
Remember that if the screen orientation changes, your activity is recreated. That means that any variables you set the last time around, which are not static, will be lost after the activity is recreated under the new orientation.
My guess is that you hit a NullPointerException here:
if(setting.getAddForPublicUserNames() == 1){
If so, it is most likely that some user action changes the "setting" variable to something other than null - you need to make sure this is set again when the activity is recreated.
The most standard method to store/retrieve the activity state between orientations is detailed here: Saving Android Activity state using Save Instance State