diff --git a/dexter/src/main/java/com/karumi/dexter/Dexter.java b/dexter/src/main/java/com/karumi/dexter/Dexter.java index d3e4c86c..66774030 100644 --- a/dexter/src/main/java/com/karumi/dexter/Dexter.java +++ b/dexter/src/main/java/com/karumi/dexter/Dexter.java @@ -126,9 +126,10 @@ private static void initialize(Context context) { if (instance == null) { AndroidPermissionService androidPermissionService = new AndroidPermissionService(); IntentProvider intentProvider = new IntentProvider(); - instance = new DexterInstance(androidPermissionService, intentProvider); + instance = new DexterInstance(context, androidPermissionService, intentProvider); + } else { + instance.setContext(context); } - instance.setContext(context); } /** diff --git a/dexter/src/main/java/com/karumi/dexter/DexterInstance.java b/dexter/src/main/java/com/karumi/dexter/DexterInstance.java index 904d46bc..3cc4b9b2 100644 --- a/dexter/src/main/java/com/karumi/dexter/DexterInstance.java +++ b/dexter/src/main/java/com/karumi/dexter/DexterInstance.java @@ -58,7 +58,7 @@ final class DexterInstance { private Activity activity; private MultiplePermissionsListener listener = EMPTY_LISTENER; - DexterInstance(AndroidPermissionService androidPermissionService, + DexterInstance(Context context, AndroidPermissionService androidPermissionService, IntentProvider intentProvider) { this.androidPermissionService = androidPermissionService; this.intentProvider = intentProvider; @@ -67,6 +67,7 @@ final class DexterInstance { this.isRequestingPermission = new AtomicBoolean(); this.rationaleAccepted = new AtomicBoolean(); this.isShowingNativeDialog = new AtomicBoolean(); + setContext(context); } void setContext(Context context) { diff --git a/dexter/src/test/java/com/karumi/dexter/DexterInstanceTest.java b/dexter/src/test/java/com/karumi/dexter/DexterInstanceTest.java index 46e7a18f..c06402bb 100644 --- a/dexter/src/test/java/com/karumi/dexter/DexterInstanceTest.java +++ b/dexter/src/test/java/com/karumi/dexter/DexterInstanceTest.java @@ -66,8 +66,7 @@ Context mockApplicationContext = mock(Context.class); when(context.getApplicationContext()).thenReturn(mockApplicationContext); asyncExecutor = new AsyncExecutor(); - dexter = new DexterInstance(androidPermissionService, intentProvider); - dexter.setContext(context); + dexter = new DexterInstance(context, androidPermissionService, intentProvider); } @Test(expected = DexterException.class) public void onNoPermissionCheckedThenThrowException() {