Skip to content

Commit e0bc8b0

Browse files
NickToropovalexandergoncharov-zz
authored andcommitted
Fixed app crash caused by multiple callback invocation from java code. (#1289)
Added CodePushUtils.log method for logging exceptions.
1 parent 21f8388 commit e0bc8b0

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

android/app/src/main/java/com/microsoft/codepush/react/CodePushDialog.java

+14-10
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,20 @@ private void showDialogInternal(String title, String message, String button1Text
5757
DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
5858
@Override
5959
public void onClick(DialogInterface dialog, int which) {
60-
dialog.cancel();
61-
switch (which) {
62-
case DialogInterface.BUTTON_POSITIVE:
63-
successCallback.invoke(0);
64-
break;
65-
case DialogInterface.BUTTON_NEGATIVE:
66-
successCallback.invoke(1);
67-
break;
68-
default:
69-
throw new CodePushUnknownException("Unknown button ID pressed.");
60+
try {
61+
dialog.cancel();
62+
switch (which) {
63+
case DialogInterface.BUTTON_POSITIVE:
64+
successCallback.invoke(0);
65+
break;
66+
case DialogInterface.BUTTON_NEGATIVE:
67+
successCallback.invoke(1);
68+
break;
69+
default:
70+
throw new CodePushUnknownException("Unknown button ID pressed.");
71+
}
72+
} catch (Throwable e) {
73+
CodePushUtils.log(e);
7074
}
7175
}
7276
};

android/app/src/main/java/com/microsoft/codepush/react/CodePushUtils.java

+4
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@ public static void log(String message) {
203203
Log.d(CodePushConstants.REACT_NATIVE_LOG_TAG, "[CodePush] " + message);
204204
}
205205

206+
public static void log(Throwable tr) {
207+
Log.e(CodePushConstants.REACT_NATIVE_LOG_TAG, "[CodePush] Exception", tr);
208+
}
209+
206210
public static void logBundleUrl(String path) {
207211
log("Loading JS bundle from \"" + path + "\"");
208212
}

0 commit comments

Comments
 (0)