标题翻译
Android map Activity gets reloaded only once, when I leave ( finish() ) another activity
问题
我正在使用Mapbox在地图中显示一些点。我启动了第二个带有结果代码的活动,这样当我完成后,我可以将第二个活动中的一些坐标发送回第一个活动,并计算路线。
问题是,只有在第一次进入第二个活动并调用finish()时,我返回的MainActivity才会被重新创建,而且这只会在第一次发生。当我再次进入并退出MainActivity时,它不会重新加载,一切正常运行。这导致我出现以下错误:
java.lang.NullPointerException: 尝试调用空对象引用上的 'void com.mapbox.mapboxsdk.maps.Style.addSource(com.mapbox.mapboxsdk.style.sources.Source)' 方法
在生成navigationMapRoute时出现上述错误。我记录了mapView和mapboxView,它们都不为空。
正如您所见,如果我在第一次进入第二个活动时尝试生成路线,它会崩溃。
这可能是我还不知道的常见情况吗?
英文翻译
I am using Mapbox to show some points in a map. I start a second activity for resultcode, so when I finish I can send some coordinates from the second into the first and calculate a route.
The problem is that only the first time that I enter the second activity and call finish(), the MainActivity that I return to gets recreated, and this happens only the first time. When I enter and exit again the MainActivity does not reload and everything works fine. This causes me to get the following error:
java.lang.NullPointerException: Attempt to invoke virtual method 'void com.mapbox.mapboxsdk.maps.Style.addSource(com.mapbox.mapboxsdk.style.sources.Source)' on a null object reference
when generating a navigationMapRoute. I logged mapView and mapboxView and none are null.
As you can see, if I try to generate a route the first time I enter the second activity it would crash.
Is it maybe a common thing I still don't know?
专注分享java语言的经验与见解,让所有开发者获益!
评论