|
19 | 19 | import android.os.Handler; |
20 | 20 | import android.os.Message; |
21 | 21 |
|
| 22 | +import android.view.ViewGroup; |
22 | 23 | import androidx.annotation.NonNull; |
23 | 24 | import androidx.annotation.Nullable; |
24 | 25 |
|
|
34 | 35 | import com.tencent.mtt.hippy.modules.javascriptmodules.HippyJavaScriptModuleInvocationHandler; |
35 | 36 | import com.tencent.mtt.hippy.modules.nativemodules.HippyNativeModuleBase; |
36 | 37 | import com.tencent.mtt.hippy.modules.nativemodules.HippyNativeModuleInfo; |
37 | | -import com.tencent.mtt.hippy.runtime.builtins.JSValue; |
38 | 38 | import com.tencent.mtt.hippy.runtime.builtins.array.JSDenseArray; |
39 | 39 | import com.tencent.mtt.hippy.serialization.PrimitiveValueDeserializer; |
40 | 40 | import com.tencent.mtt.hippy.serialization.compatible.Deserializer; |
|
46 | 46 | import com.tencent.mtt.hippy.utils.LogUtils; |
47 | 47 |
|
48 | 48 | import com.tencent.mtt.hippy.utils.UIThreadUtils; |
| 49 | +import java.lang.ref.WeakReference; |
49 | 50 | import java.lang.reflect.Proxy; |
50 | 51 | import java.nio.ByteBuffer; |
51 | 52 | import java.util.HashMap; |
@@ -437,14 +438,20 @@ private void onCallNativeFinished(@Nullable HippyCallNativeParams params) { |
437 | 438 | adapter.onCallNativeFinished(mContext.getComponentName(), params); |
438 | 439 | } |
439 | 440 |
|
440 | | - private void removeRootView(@NonNull final JSDenseArray roots) { |
441 | | - UIThreadUtils.runOnUiThread(new Runnable() { |
442 | | - @Override |
443 | | - public void run() { |
444 | | - if (roots.size() > 0) { |
| 441 | + private void removeRootView(@Nullable final JSDenseArray roots) { |
| 442 | + final WeakReference<HippyEngineContext> engineContextRef = new WeakReference<>(mContext); |
| 443 | + UIThreadUtils.runOnUiThread(() -> { |
| 444 | + HippyEngineContext engineContext = engineContextRef.get(); |
| 445 | + if (engineContext != null) { |
| 446 | + if (roots != null && roots.size() > 0) { |
445 | 447 | Object valueObj = roots.get(0); |
446 | 448 | if (valueObj instanceof Integer) { |
447 | | - ((HippyInstanceLifecycleEventListener) mContext).onInstanceDestroy((Integer) valueObj); |
| 449 | + ((HippyInstanceLifecycleEventListener) engineContext).onInstanceDestroy((Integer) valueObj); |
| 450 | + } |
| 451 | + } else { |
| 452 | + ViewGroup rootView = engineContext.getRootView(); |
| 453 | + if (rootView != null) { |
| 454 | + ((HippyInstanceLifecycleEventListener) engineContext).onInstanceDestroy(rootView.getId()); |
448 | 455 | } |
449 | 456 | } |
450 | 457 | } |
|
0 commit comments