21
21
import java .io .FileWriter ;
22
22
import java .io .File ;
23
23
import java .io .IOException ;
24
- import java .util .ArrayList ;
24
+ import java .util .Collections ;
25
+ import java .util .Iterator ;
25
26
26
27
import java .util .zip .GZIPInputStream ;
27
28
@@ -380,11 +381,11 @@ public interface NewIntentListener {
380
381
void onNewIntent (Intent intent );
381
382
}
382
383
383
- private ArrayList <NewIntentListener > newIntentListeners = null ;
384
+ private List <NewIntentListener > newIntentListeners = null ;
384
385
385
386
public void registerNewIntentListener (NewIntentListener listener ) {
386
387
if ( this .newIntentListeners == null )
387
- this .newIntentListeners = new ArrayList <NewIntentListener >();
388
+ this .newIntentListeners = Collections . synchronizedList ( new ArrayList <NewIntentListener >() );
388
389
this .newIntentListeners .add (listener );
389
390
}
390
391
@@ -400,8 +401,12 @@ protected void onNewIntent(Intent intent) {
400
401
return ;
401
402
if ( this .mView != null )
402
403
this .mView .onResume ();
403
- for ( NewIntentListener listener : this .newIntentListeners )
404
- listener .onNewIntent (intent );
404
+ synchronized ( this .newIntentListeners ) {
405
+ Iterator <NewIntentListener > iterator = this .newIntentListeners .iterator ();
406
+ while ( iterator .hasNext () ) {
407
+ (iterator .next ()).onNewIntent (intent );
408
+ }
409
+ }
405
410
}
406
411
407
412
//----------------------------------------------------------------------------
@@ -412,11 +417,11 @@ public interface ActivityResultListener {
412
417
void onActivityResult (int requestCode , int resultCode , Intent data );
413
418
}
414
419
415
- private ArrayList <ActivityResultListener > activityResultListeners = null ;
420
+ private List <ActivityResultListener > activityResultListeners = null ;
416
421
417
422
public void registerActivityResultListener (ActivityResultListener listener ) {
418
423
if ( this .activityResultListeners == null )
419
- this .activityResultListeners = new ArrayList <ActivityResultListener >();
424
+ this .activityResultListeners = Collections . synchronizedList ( new ArrayList <ActivityResultListener >() );
420
425
this .activityResultListeners .add (listener );
421
426
}
422
427
@@ -432,8 +437,11 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent)
432
437
return ;
433
438
if ( this .mView != null )
434
439
this .mView .onResume ();
435
- for ( ActivityResultListener listener : this .activityResultListeners )
436
- listener .onActivityResult (requestCode , resultCode , intent );
440
+ synchronized ( this .activityResultListeners ) {
441
+ Iterator <ActivityResultListener > iterator = this .activityResultListeners .iterator ();
442
+ while ( iterator .hasNext () )
443
+ (iterator .next ()).onActivityResult (requestCode , resultCode , intent );
444
+ }
437
445
}
438
446
439
447
//----------------------------------------------------------------------------
0 commit comments