From 1a6b730146c62f7437a6dce9d46b232169ff1348 Mon Sep 17 00:00:00 2001 From: "pengfei.zhou" Date: Thu, 27 Feb 2020 13:40:02 +0800 Subject: [PATCH] feat:remove Context instance before js destory --- .../src/main/java/pub/doric/DoricContext.java | 32 ++++++------------- .../java/pub/doric/DoricContextManager.java | 2 +- doric-iOS/Pod/Classes/DoricContextManager.m | 9 +++--- 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/doric-android/doric/src/main/java/pub/doric/DoricContext.java b/doric-android/doric/src/main/java/pub/doric/DoricContext.java index abb5236b..dcbe4d31 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricContext.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricContext.java @@ -162,31 +162,17 @@ public class DoricContext { public void teardown() { callEntity(DoricConstant.DORIC_ENTITY_DESTROY); - DoricContextManager.getInstance().destroyContext(this).setCallback(new AsyncResult.Callback() { + getDriver().asyncCall(new Callable() { @Override - public void onResult(Boolean result) { - + public Object call() { + for (DoricJavaPlugin javaPlugin : mPluginMap.values()) { + javaPlugin.onTearDown(); + } + mPluginMap.clear(); + return null; } - - @Override - public void onError(Throwable t) { - - } - - @Override - public void onFinish() { - getDriver().asyncCall(new Callable() { - @Override - public Object call() { - for (DoricJavaPlugin javaPlugin : mPluginMap.values()) { - javaPlugin.onTearDown(); - } - mPluginMap.clear(); - return null; - } - }, ThreadMode.UI); - } - }); + }, ThreadMode.UI); + DoricContextManager.getInstance().destroyContext(this); } public DoricJavaPlugin obtainPlugin(DoricMetaInfo doricMetaInfo) { diff --git a/doric-android/doric/src/main/java/pub/doric/DoricContextManager.java b/doric-android/doric/src/main/java/pub/doric/DoricContextManager.java index a3046720..ec462fc7 100644 --- a/doric-android/doric/src/main/java/pub/doric/DoricContextManager.java +++ b/doric-android/doric/src/main/java/pub/doric/DoricContextManager.java @@ -57,6 +57,7 @@ public class DoricContextManager { } AsyncResult destroyContext(final DoricContext context) { + doricContextMap.remove(context.getContextId()); final AsyncResult result = new AsyncResult<>(); context.getDriver().destroyContext(context.getContextId()).setCallback(new AsyncResult.Callback() { @Override @@ -71,7 +72,6 @@ public class DoricContextManager { @Override public void onFinish() { - doricContextMap.remove(context.getContextId()); } }); return result; diff --git a/doric-iOS/Pod/Classes/DoricContextManager.m b/doric-iOS/Pod/Classes/DoricContextManager.m index a6ddc2cf..808ebf6a 100644 --- a/doric-iOS/Pod/Classes/DoricContextManager.m +++ b/doric-iOS/Pod/Classes/DoricContextManager.m @@ -70,11 +70,10 @@ - (DoricContext *)getContext:(NSString *)contextId { - (void)destroyContext:(DoricContext *)context { NSString *contextId = context.contextId; - [context.driver destroyContext:contextId].finishCallback = ^{ - dispatch_sync(self.mapQueue, ^() { - [self.doricContextMap removeObjectForKey:contextId]; - }); - }; + dispatch_sync(self.mapQueue, ^() { + [self.doricContextMap removeObjectForKey:contextId]; + }); + [context.driver destroyContext:contextId]; } - (NSArray *)aliveContexts {