diff --git a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/hook/BnHooker.java b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/hook/BnHooker.java index 51177489d3..82e014560a 100644 --- a/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/hook/BnHooker.java +++ b/libraries/map-amap/src/main/java/com/mogo/map/impl/amap/hook/BnHooker.java @@ -23,6 +23,8 @@ public class BnHooker implements InvocationHandler { private static final String TAG = "BnHooker"; private Object host; + private Method getGLMapEngineMethod; + private GLMapEngine glMapEngineObject; public BnHooker( AMap map ) throws Exception { @@ -47,11 +49,17 @@ public class BnHooker implements InvocationHandler { } public void clearAllMessages() throws Exception { - Method method = host.getClass().getDeclaredMethod( "getGLMapEngine" ); - method.setAccessible( true ); - GLMapEngine glMapEngine = ( GLMapEngine ) method.invoke( host ); - clearMessageList( "mStateMessageList", glMapEngine ); - clearMessageList( "mAnimateStateMessageList", glMapEngine ); + if ( glMapEngineObject == null ) { + if ( getGLMapEngineMethod == null ) { + getGLMapEngineMethod = host.getClass().getDeclaredMethod( "getGLMapEngine" ); + getGLMapEngineMethod.setAccessible( true ); + } + glMapEngineObject = ( GLMapEngine ) getGLMapEngineMethod.invoke( host ); + } + if ( glMapEngineObject != null ) { + clearMessageList( "mStateMessageList", glMapEngineObject ); + clearMessageList( "mAnimateStateMessageList", glMapEngineObject ); + } } private void clearMessageList( String filedName, Object obj ) throws Exception {