问题描述
在我们的cordova 应用程序中,我们使用的是打开另一个活动的SDK。当活动返回时,我们尝试使用 CallbackContext 将数据发回。我们看到很多时候 CallbackContext currentCallbackContext 为 null 并且应用程序崩溃。我们如何确保 currentCallbackContext 不会丢失?
public class PluginBridge extends CordovaPlugin {
private CallbackContext currentCallbackContext = null;
public void initialize(CordovaInterface cordova,CordovaWebView webView) {
super.initialize(cordova,webView);
Log.d(TAG,"Initializing SDK");
}
public boolean execute(String action,JSONArray args,final CallbackContext callbackContext) throws JSONException {
if(action.equals("init")) {
this.currentCallbackContext = callbackContext;
Intent intent = new Intent("com.plugin.sdk.someActivity");
intent.putExtra("token",token);
cordova.startActivityForResult(this,intent,1);
}
}
@Override
public void onActivityResult(final int requestCode,final int resultCode,final Intent data) {
if(resultCode == cordova.getActivity().RESULT_OK){
PluginResult result = new PluginResult(PluginResult.Status.OK,data.getExtras().getString("data")); // data parameter will be send from the other activity.
result.setKeepCallback(true);
currentCallbackContext.sendpluginResult(result);
return;
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)