diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerDialogModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerDialogModule.java index 026e752a58df2a..d44c4f8b9bec05 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerDialogModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/datepicker/DatePickerDialogModule.java @@ -7,6 +7,7 @@ package com.facebook.react.modules.datepicker; +import android.app.Activity; import android.app.DatePickerDialog.OnDateSetListener; import android.content.DialogInterface; import android.content.DialogInterface.OnDismissListener; @@ -101,13 +102,16 @@ public void onDismiss(DialogInterface dialog) { */ @ReactMethod public void open(@Nullable final ReadableMap options, Promise promise) { - FragmentActivity activity = (FragmentActivity) getCurrentActivity(); - if (activity == null) { + Activity raw_activity = getCurrentActivity(); + if (raw_activity == null || !(raw_activity instanceof FragmentActivity)) { promise.reject( - ERROR_NO_ACTIVITY, "Tried to open a DatePicker dialog while not attached to an Activity"); + ERROR_NO_ACTIVITY, + "Tried to open a DatePicker dialog while not attached to a FragmentActivity"); return; } + FragmentActivity activity = (FragmentActivity) raw_activity; + FragmentManager fragmentManager = activity.getSupportFragmentManager(); DialogFragment oldFragment = (DialogFragment) fragmentManager.findFragmentByTag(FRAGMENT_TAG); if (oldFragment != null) { diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/dialog/DialogModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/dialog/DialogModule.java index 6dea0d63740a06..437336f0ab02f1 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/dialog/DialogModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/dialog/DialogModule.java @@ -234,7 +234,7 @@ public void run() { */ private @Nullable FragmentManagerHelper getFragmentManagerHelper() { Activity activity = getCurrentActivity(); - if (activity == null) { + if (activity == null || !(activity instanceof FragmentActivity)) { return null; } return new FragmentManagerHelper(((FragmentActivity) activity).getSupportFragmentManager()); diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/TimePickerDialogModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/TimePickerDialogModule.java index f0c55360ba53d9..412cf5d369aff9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/TimePickerDialogModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/timepicker/TimePickerDialogModule.java @@ -7,6 +7,7 @@ package com.facebook.react.modules.timepicker; +import android.app.Activity; import android.app.TimePickerDialog.OnTimeSetListener; import android.content.DialogInterface; import android.content.DialogInterface.OnDismissListener; @@ -89,12 +90,16 @@ public void onDismiss(DialogInterface dialog) { @ReactMethod public void open(@Nullable final ReadableMap options, Promise promise) { - FragmentActivity activity = (FragmentActivity) getCurrentActivity(); - if (activity == null) { + Activity raw_activity = getCurrentActivity(); + if (raw_activity == null || !(raw_activity instanceof FragmentActivity)) { promise.reject( - ERROR_NO_ACTIVITY, "Tried to open a TimePicker dialog while not attached to an Activity"); + ERROR_NO_ACTIVITY, + "Tried to open a DatePicker dialog while not attached to a FragmentActivity"); return; } + + FragmentActivity activity = (FragmentActivity) raw_activity; + // We want to support both android.app.Activity and the pre-Honeycomb FragmentActivity // (for apps that use it for legacy reasons). This unfortunately leads to some code duplication. FragmentManager fragmentManager = activity.getSupportFragmentManager();