@@ -149,7 +149,7 @@ public OptimizelyClient initialize(@NonNull Context context, @NonNull String dat
149
149
// the user can instantiate with the latest datafile
150
150
final Intent intent = new Intent (context .getApplicationContext (), DataFileService .class );
151
151
if (dataFileServiceConnection == null ) {
152
- this .dataFileServiceConnection = new DataFileServiceConnection (this );
152
+ this .dataFileServiceConnection = new DataFileServiceConnection (this , context );
153
153
context .getApplicationContext ().bindService (intent , dataFileServiceConnection , Context .BIND_AUTO_CREATE );
154
154
}
155
155
@@ -239,7 +239,7 @@ public void initialize(@NonNull Context context, @NonNull OptimizelyStartListene
239
239
this .optimizelyStartListener = optimizelyStartListener ;
240
240
final Intent intent = new Intent (context .getApplicationContext (), DataFileService .class );
241
241
if (dataFileServiceConnection == null ) {
242
- this .dataFileServiceConnection = new DataFileServiceConnection (this );
242
+ this .dataFileServiceConnection = new DataFileServiceConnection (this , context );
243
243
context .getApplicationContext ().bindService (intent , dataFileServiceConnection , Context .BIND_AUTO_CREATE );
244
244
}
245
245
}
@@ -265,6 +265,7 @@ public void stop(@NonNull Context context) {
265
265
}
266
266
if (dataFileServiceConnection != null && dataFileServiceConnection .isBound ()) {
267
267
context .getApplicationContext ().unbindService (dataFileServiceConnection );
268
+ dataFileServiceConnection = null ;
268
269
}
269
270
270
271
this .optimizelyStartListener = null ;
@@ -456,10 +457,12 @@ public void onActivityDestroyed(Activity activity) {
456
457
static class DataFileServiceConnection implements ServiceConnection {
457
458
458
459
@ NonNull private final OptimizelyManager optimizelyManager ;
460
+ @ NonNull private final Context context ;
459
461
private boolean bound = false ;
460
462
461
- DataFileServiceConnection (@ NonNull OptimizelyManager optimizelyManager ) {
463
+ DataFileServiceConnection (@ NonNull OptimizelyManager optimizelyManager , @ NonNull Context context ) {
462
464
this .optimizelyManager = optimizelyManager ;
465
+ this .context = context ;
463
466
}
464
467
465
468
/**
@@ -522,6 +525,7 @@ public void onDataFileLoaded(@Nullable String dataFile) {
522
525
@ Override
523
526
public void onServiceDisconnected (ComponentName arg0 ) {
524
527
bound = false ;
528
+ optimizelyManager .stop (context );
525
529
}
526
530
527
531
boolean isBound () {
0 commit comments