Skip to content

Commit b43eeb6

Browse files
committed
fix(android): removeRootView params may be null
1 parent a6cc90d commit b43eeb6

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

framework/android/src/main/java/com/tencent/mtt/hippy/modules/HippyModuleManagerImpl.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import android.os.Handler;
2020
import android.os.Message;
2121

22+
import android.view.ViewGroup;
2223
import androidx.annotation.NonNull;
2324
import androidx.annotation.Nullable;
2425

@@ -34,7 +35,6 @@
3435
import com.tencent.mtt.hippy.modules.javascriptmodules.HippyJavaScriptModuleInvocationHandler;
3536
import com.tencent.mtt.hippy.modules.nativemodules.HippyNativeModuleBase;
3637
import com.tencent.mtt.hippy.modules.nativemodules.HippyNativeModuleInfo;
37-
import com.tencent.mtt.hippy.runtime.builtins.JSValue;
3838
import com.tencent.mtt.hippy.runtime.builtins.array.JSDenseArray;
3939
import com.tencent.mtt.hippy.serialization.PrimitiveValueDeserializer;
4040
import com.tencent.mtt.hippy.serialization.compatible.Deserializer;
@@ -46,6 +46,7 @@
4646
import com.tencent.mtt.hippy.utils.LogUtils;
4747

4848
import com.tencent.mtt.hippy.utils.UIThreadUtils;
49+
import java.lang.ref.WeakReference;
4950
import java.lang.reflect.Proxy;
5051
import java.nio.ByteBuffer;
5152
import java.util.HashMap;
@@ -437,14 +438,20 @@ private void onCallNativeFinished(@Nullable HippyCallNativeParams params) {
437438
adapter.onCallNativeFinished(mContext.getComponentName(), params);
438439
}
439440

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) {
445447
Object valueObj = roots.get(0);
446448
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());
448455
}
449456
}
450457
}

0 commit comments

Comments
 (0)