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
If you don't want the activity to be recreated when orientation changes. Insert the following line in the AndroidManifest.xml.
android:configChanges="keyboardHidden|orientation
example:
<activity android:name=".FABSLogin" android:label="@string/app_name"
android:theme="@style/Theme.NoWindowTitle" android:noHistory="true" **android:configChanges="keyboardHidden|orientation**">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
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
When you change orientation, android restart your activity, you need to save the estate with
onSaveInstanceState
and recover with
savedInstanceState