MapView by Here crashes when calling mapView.onCreate in a single Activity architecture

断了今生、忘了曾经 提交于 2020-08-10 13:39:14

问题


I'm using a single-activity architecture, with Fragments as screen, and using the Navigation component. In the first fragment, I initialize the map in onViewCreated and destroy it in onDestroyView.

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
    super.onViewCreated(view, savedInstanceState)
    mapView.onCreate(savedInstanceState)
    loadMapScene()
}

override fun onDestroyView() {
    mapView?.onDestroy()
    super.onDestroyView()
}

From this fragment, user can navigate to another fragment with a map, which also calls mapView.onCreate in its onViewCreated. However, using the newest (4.4.0.2.2340) Here Maps Lite library it crashes, because:

MapViewLite.class

private static boolean mInstanceActivated;

public void onCreate(@Nullable Bundle var1) {
    if (!mInstanceActivated) { 
        //various initializations
        mInstanceActivated = true;
    } else {
        throw new RuntimeException("Only one MapViewLite instance can be created at a time");
    }
}

public void onDestroy() {
    this.mNativeRenderer.dispose();
    this.mNativeRenderer = null;
     // setting to nulls
    mInstanceActivated = false;
}

In the normal Fragment lifecycle, onViewCreated of the fragment navigated to happens before even onPause (not to mention onDestroyView) of the fragment navigated from. That means the second mapView.onCreate is called before the first mapView.onDestroy() and thus its RuntimeException is thrown. Interestingly, it didn't crash in the 4.3.3.0.2052 version (to which I reverted for now). Could you please make the Here Lite MapView usable in a single Activity architecture?

来源:https://stackoverflow.com/questions/63048997/mapview-by-here-crashes-when-calling-mapview-oncreate-in-a-single-activity-archi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!