* [android] invoke callbacks when instance will be destroy
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/b80a7b59 Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/b80a7b59 Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/b80a7b59 Branch: refs/heads/0.16-dev Commit: b80a7b5999a5f69a1744f2d1043fbf0cdfe7f565 Parents: 4b0a600 Author: misakuo <misa...@apache.org> Authored: Mon Aug 14 12:02:29 2017 +0800 Committer: misakuo <misa...@apache.org> Committed: Mon Aug 14 12:02:29 2017 +0800 ---------------------------------------------------------------------- .../main/java/com/taobao/weex/WXSDKManager.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/b80a7b59/android/sdk/src/main/java/com/taobao/weex/WXSDKManager.java ---------------------------------------------------------------------- diff --git a/android/sdk/src/main/java/com/taobao/weex/WXSDKManager.java b/android/sdk/src/main/java/com/taobao/weex/WXSDKManager.java index fc3fe75..10b1873 100644 --- a/android/sdk/src/main/java/com/taobao/weex/WXSDKManager.java +++ b/android/sdk/src/main/java/com/taobao/weex/WXSDKManager.java @@ -53,6 +53,7 @@ import com.taobao.weex.utils.WXLogUtils; import com.taobao.weex.utils.WXUtils; import java.io.File; +import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -91,6 +92,8 @@ public class WXSDKManager { // Tell weexv8 to initialize v8, default is true. private boolean mNeedInitV8 = true; + private List<InstanceLifeCycleCallbacks> mLifeCycleCallbacks; + private static final int DEFAULT_VIEWPORT_WIDTH = 750; private WXSDKManager() { @@ -288,6 +291,11 @@ public class WXSDKManager { if (!WXUtils.isUiThread()) { throw new WXRuntimeException("[WXSDKManager] destroyInstance error"); } + if (mLifeCycleCallbacks != null) { + for (InstanceLifeCycleCallbacks callbacks : mLifeCycleCallbacks) { + callbacks.onInstanceDestroyed(instanceId); + } + } mWXRenderManager.removeRenderStatement(instanceId); mWXDomManager.removeDomStatement(instanceId); mBridgeManager.destroyInstance(instanceId); @@ -429,4 +437,15 @@ public class WXSDKManager { public ITracingAdapter getTracingAdapter() { return mTracingAdapter; } + + public void registerInstanceLifeCycleCallbacks(InstanceLifeCycleCallbacks callbacks) { + if (mLifeCycleCallbacks == null) { + mLifeCycleCallbacks = new ArrayList<>(); + } + mLifeCycleCallbacks.add(callbacks); + } + + public interface InstanceLifeCycleCallbacks { + void onInstanceDestroyed(String instanceId); + } }