From 67d9a7bae971c1a6cee58fadf9e5b27f6763da33 Mon Sep 17 00:00:00 2001 From: "Yu Zheng(Sam)" Date: Mon, 16 May 2016 12:45:55 -0700 Subject: [PATCH] =?UTF-8?q?Mark=20SupportAlertFragment=20and=20AlertFragme?= =?UTF-8?q?nt=20as=20Public=20to=20fix=20crash=20is=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Summary: Hi, This changelist is for fixing a crash issue on Android devices. For detail please see, https://github.com/facebook/react-native/issues/7080 In short, the crash occurred when a RN app with a Alert dialog shown at front switches back after it is destroyed at background due to lack of phone memory. My fix is to let those Alert fragment classes accessible from android.support.v4.app.Fragment instantiate() function, so that it won't crash. And since other UI will be reloaded whatever, mListener is set to null to avoid any callback happen. Closes https://github.com/facebook/react-native/pull/7105 Differential Revision: D3212435 Pulled By: mkonicek fbshipit-source-id: d900a33a4f0fd49258be94c277def55555ec8d73 --- .../com/facebook/react/modules/dialog/AlertFragment.java | 6 +++++- .../facebook/react/modules/dialog/SupportAlertFragment.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/dialog/AlertFragment.java b/ReactAndroid/src/main/java/com/facebook/react/modules/dialog/AlertFragment.java index 98dd9cc0a..9f23515c6 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/dialog/AlertFragment.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/dialog/AlertFragment.java @@ -21,7 +21,7 @@ import android.os.Bundle; /** * A fragment used to display the dialog. */ -/* package */ class AlertFragment extends DialogFragment implements DialogInterface.OnClickListener { +public class AlertFragment extends DialogFragment implements DialogInterface.OnClickListener { /* package */ static final String ARG_TITLE = "title"; /* package */ static final String ARG_MESSAGE = "message"; @@ -32,6 +32,10 @@ import android.os.Bundle; private final @Nullable DialogModule.AlertFragmentListener mListener; + public AlertFragment() { + mListener = null; + } + public AlertFragment(@Nullable DialogModule.AlertFragmentListener listener, Bundle arguments) { mListener = listener; setArguments(arguments); diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/dialog/SupportAlertFragment.java b/ReactAndroid/src/main/java/com/facebook/react/modules/dialog/SupportAlertFragment.java index fb987cd05..f93c8afa7 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/dialog/SupportAlertFragment.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/dialog/SupportAlertFragment.java @@ -21,10 +21,14 @@ import android.support.v4.app.DialogFragment; * {@link AlertFragment} for apps that use the Support FragmentActivity and FragmentManager * for legacy reasons. */ -/* package */ class SupportAlertFragment extends DialogFragment implements DialogInterface.OnClickListener { +public class SupportAlertFragment extends DialogFragment implements DialogInterface.OnClickListener { private final @Nullable DialogModule.AlertFragmentListener mListener; + public SupportAlertFragment() { + mListener = null; + } + public SupportAlertFragment(@Nullable DialogModule.AlertFragmentListener listener, Bundle arguments) { mListener = listener; setArguments(arguments);