Skip to content

Commit 1fca206

Browse files
committed
fix: android crash when init was not called on main thread
1 parent a6391d0 commit 1fca206

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/android/io/branch/BranchSDK.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,76 +91,76 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
9191

9292
if (action.equals("setDebug")) {
9393
if (args.length() == 1) {
94-
cordova.getThreadPool().execute(r);
94+
cordova.getActivity().runOnUiThread(r);
9595
}
9696
return true;
9797
} else if (action.equals("initSession")) {
98-
cordova.getThreadPool().execute(r);
98+
cordova.getActivity().runOnUiThread(r);
9999
return true;
100100
} else if (action.equals("setMixpanelToken")) {
101-
cordova.getThreadPool().execute(r);
101+
cordova.getActivity().runOnUiThread(r);
102102
return true;
103103
} else {
104104
if (this.instance != null) {
105105
if (action.equals("setIdentity")) {
106-
cordova.getThreadPool().execute(r);
106+
cordova.getActivity().runOnUiThread(r);
107107
return true;
108108
} else if (action.equals("userCompletedAction")) {
109109
if (args.length() < 1 && args.length() > 2) {
110110
callbackContext.error(String.format("Parameter mismatched. 1-2 is required but %d is given", args.length()));
111111
return false;
112112
}
113-
cordova.getThreadPool().execute(r);
113+
cordova.getActivity().runOnUiThread(r);
114114
return true;
115115
} else if (action.equals("sendCommerceEvent")) {
116116
if (args.length() < 1 && args.length() > 2) {
117117
callbackContext.error(String.format("Parameter mismatched. 1-2 is required but %d is given", args.length()));
118118
return false;
119119
}
120-
cordova.getThreadPool().execute(r);
120+
cordova.getActivity().runOnUiThread(r);
121121
return true;
122122
} else if (action.equals("getFirstReferringParams")) {
123-
cordova.getThreadPool().execute(r);
123+
cordova.getActivity().runOnUiThread(r);
124124
return true;
125125
} else if (action.equals("getLatestReferringParams")) {
126-
cordova.getThreadPool().execute(r);
126+
cordova.getActivity().runOnUiThread(r);
127127
return true;
128128
} else if (action.equals("logout")) {
129-
cordova.getThreadPool().execute(r);
129+
cordova.getActivity().runOnUiThread(r);
130130
return true;
131131
} else if (action.equals("loadRewards")) {
132-
cordova.getThreadPool().execute(r);
132+
cordova.getActivity().runOnUiThread(r);
133133
return true;
134134
} else if (action.equals("redeemRewards")) {
135135
if (args.length() < 1 && args.length() > 2) {
136136
callbackContext.error(String.format("Parameter mismatched. 1-2 is required but %d is given", args.length()));
137137
return false;
138138
}
139-
cordova.getThreadPool().execute(r);
139+
cordova.getActivity().runOnUiThread(r);
140140
return true;
141141
} else if (action.equals("getCreditHistory")) {
142-
cordova.getThreadPool().execute(r);
142+
cordova.getActivity().runOnUiThread(r);
143143
return true;
144144
} else if (action.equals("createBranchUniversalObject")) {
145145
if (args.length() != 1) {
146146
callbackContext.error(String.format("Parameter mismatched. 1 is required but %d is given", args.length()));
147147
return false;
148148
}
149-
cordova.getThreadPool().execute(r);
149+
cordova.getActivity().runOnUiThread(r);
150150
return true;
151151
} else if (action.equals(("generateShortUrl"))) {
152152
if (args.length() != 3) {
153153
callbackContext.error(String.format("Parameter mismatched. 3 is required but %d is given", args.length()));
154154
return false;
155155
}
156-
cordova.getThreadPool().execute(r);
156+
cordova.getActivity().runOnUiThread(r);
157157
return true;
158158
} else if (action.equals("registerView")) {
159159
if (args.length() != 1) {
160160
callbackContext.error(String.format("Parameter mismatched. 1 is required but %d is given", args.length()));
161161
return false;
162162
}
163-
cordova.getThreadPool().execute(r);
163+
cordova.getActivity().runOnUiThread(r);
164164
return true;
165165
} else if (action.equals("showShareSheet")) {
166166
if (args.length() < 3) {

0 commit comments

Comments
 (0)