@@ -101,6 +101,8 @@ public enum DialogState {
101
101
private boolean alertDismissActivity ;
102
102
private boolean progressDismissActivity ;
103
103
104
+ private boolean onSaveInstanceStateCalled ;
105
+
104
106
// Make default constructor private
105
107
private AlertNProgessMsgFragmentMger () {
106
108
}
@@ -115,6 +117,7 @@ public AlertNProgessMsgFragmentMger(String appName, String initAlertDialogTag,
115
117
progressDismissActivity ) {
116
118
mDialogState = DialogState .None ;
117
119
dialogsClearedForFragmentShutdown = false ;
120
+ onSaveInstanceStateCalled = false ;
118
121
this .appName = appName ;
119
122
this .alertDialogTag = initAlertDialogTag ;
120
123
this .progressDialogTag = initDialogProgressTag ;
@@ -128,6 +131,7 @@ public AlertNProgessMsgFragmentMger(String appName, String initAlertDialogTag,
128
131
* @param bundleOfState
129
132
*/
130
133
public void addStateToSaveStateBundle (Bundle bundleOfState ) {
134
+ onSaveInstanceStateCalled = true ;
131
135
bundleOfState .putString (APPNAME_KEY , appName );
132
136
bundleOfState .putString (ALERT_TAG_KEY , alertDialogTag );
133
137
bundleOfState .putString (PROGRESS_TAG_KEY , progressDialogTag );
@@ -145,6 +149,7 @@ public void addStateToSaveStateBundle(Bundle bundleOfState) {
145
149
*/
146
150
public void restoreDialog (FragmentManager fragmentManager , int fragmentId ) {
147
151
dialogsClearedForFragmentShutdown = false ;
152
+ onSaveInstanceStateCalled = false ;
148
153
switch (mDialogState ) {
149
154
case Progress :
150
155
restoreProgressDialog (fragmentManager );
@@ -159,7 +164,7 @@ public void restoreDialog(FragmentManager fragmentManager, int fragmentId) {
159
164
}
160
165
161
166
public boolean displayingProgressDialog () {
162
- return mDialogState == DialogState .Progress && !dialogsClearedForFragmentShutdown ;
167
+ return mDialogState == DialogState .Progress && !dialogsClearedForFragmentShutdown && ! onSaveInstanceStateCalled ;
163
168
}
164
169
165
170
public boolean hasDialogBeenCreated () {
@@ -212,13 +217,22 @@ public void createAlertDialog(String title, String message, FragmentManager frag
212
217
throw new IllegalArgumentException ("FragmentManager cannot be null" );
213
218
}
214
219
220
+ if (dialogsClearedForFragmentShutdown ) {
221
+ throw new IllegalStateException ("Getting an create" +
222
+ "alert when the dialogs have been cleared for shutdown" );
223
+ }
224
+
225
+ if (onSaveInstanceStateCalled ) {
226
+ WebLogger .getLogger (appName ).e (TAG , "Trying to create an Alert Dialog after" +
227
+ "onSaveStateInstance is called" );
228
+ }
229
+
215
230
if (mDialogState == DialogState .Progress ) {
216
231
dismissProgressDialog (fragmentManager );
217
232
}
218
233
219
234
currentTitle = title ;
220
235
currentMessage = message ;
221
- dialogsClearedForFragmentShutdown = false ;
222
236
restoreAlertDialog (fragmentManager , fragmentId );
223
237
}
224
238
@@ -238,13 +252,22 @@ public void createProgressDialog(String title, String message, FragmentManager f
238
252
throw new IllegalArgumentException ("FragmentManager cannot be null" );
239
253
}
240
254
255
+ if (dialogsClearedForFragmentShutdown ) {
256
+ throw new IllegalStateException ("Getting an create" +
257
+ "progress when the dialogs have been cleared for shutdown" );
258
+ }
259
+
260
+ if (onSaveInstanceStateCalled ) {
261
+ WebLogger .getLogger (appName ).e (TAG , "Trying to create an Progress Dialog after" +
262
+ "onSaveStateInstance is called" );
263
+ }
264
+
241
265
if (mDialogState == DialogState .Alert ) {
242
266
dismissAlertDialog (fragmentManager );
243
267
}
244
268
245
269
currentTitle = title ;
246
270
currentMessage = message ;
247
- dialogsClearedForFragmentShutdown = false ;
248
271
restoreProgressDialog (fragmentManager );
249
272
}
250
273
@@ -262,6 +285,12 @@ public void updateProgressDialogMessage(String message, FragmentManager fragment
262
285
throw new IllegalArgumentException ("FragmentManager cannot be null" );
263
286
}
264
287
288
+ if (onSaveInstanceStateCalled ) {
289
+ // we are in the middle of shutting down, update will be lost
290
+ WebLogger .getLogger (appName ).e (TAG , "Trying to Update an Progress Dialog after" +
291
+ "onSaveStateInstance is called" );
292
+ }
293
+
265
294
if (dialogsClearedForFragmentShutdown ) {
266
295
throw new IllegalStateException ("Getting an update when the dialogs have been cleared "
267
296
+ "for shutdown, should check displayingProgressDialog()" );
@@ -295,6 +324,13 @@ public void updateProgressDialogMessage(String message, int progressStep, int ma
295
324
throw new IllegalArgumentException ("FragmentManager cannot be null" );
296
325
}
297
326
327
+ if (onSaveInstanceStateCalled ) {
328
+ // we are in the middle of shutting down, update will be lost
329
+ WebLogger .getLogger (appName ).e (TAG , "Trying to Update an Progress Dialog after" +
330
+ "onSaveStateInstance is called" );
331
+ return ;
332
+ }
333
+
298
334
if (dialogsClearedForFragmentShutdown ) {
299
335
throw new IllegalStateException ("Getting an update when the dialogs have been cleared "
300
336
+ "for shutdown, should check displayingProgressDialog()" );
0 commit comments