Android地图V2图形页面定制的片断内(NPE)片断、图形、页面、地图

由网友(记忆深埋心底)分享简介:我不想使用或扩展 SupportMapFragment 或 MapFragment 。我有我自己的基类,在这一堆code。I do not want to use or extend SupportMapFragment or MapFragment. I have my own base class with a...

我不想使用或扩展 SupportMapFragment MapFragment 。我有我自己的基类,在这一堆code。

I do not want to use or extend SupportMapFragment or MapFragment. I have my own base class with a bunch of code in it.

该文件明确指出,当有人使用图形页面本身,所有相应的生命周期方法(的onCreate() onResume()等)应该被调用。

The documentation clearly states that when someone uses MapView by itself, all corresponding lifecycle methods (onCreate() onResume() etc.) should be called.

大多数在片段的生命周期方法类似于活动但是当我来​​回切换之间我的片段我最终能得到一个模糊NPE在的onDestroy() onResume()的方法。

Most of the lifecycle methods in a Fragment are similar to an Activity but when I switch back and forth between my Fragment I eventually get an obfuscated NPE in onDestroy() or in onResume() methods.

所有提供使用活动的样本图形页面而不是一个自定义的片段

All the samples provided use an Activity with a MapView but not a custom Fragment.

已经有人做过了吗?你能提供一个图形页面在自己的片段类样品code?

Has someone done that already? Can you provide sample code of a MapView in your own Fragmentclass?

推荐答案

我成功地在包括图形页面(V2)在自定义的片段本身嵌入在ViewPager。在我的情况下,图形页面包含在片段布局文件。我不得不呼吁MapView的生命周期方法(的onCreate()名为 onCreateView()从片段),并手动调用 MapsInitializer.initialize(上下文)来避免 NullPointerException异常从类BitmapDesc​​riptorFactory(获取位图标记)。最后这招很奇怪,我不知道为什么地图系统未正确初始化本身没有这个电话,也许是在目前的版本只是一个错误...

I succeeded in including a MapView (v2) in a custom Fragment itself embedded in a ViewPager. In my case, the MapView is included in the Fragment layout file. I have had to call lifecycle methods on MapView (onCreate() called onCreateView() from the Fragment), and to call manually MapsInitializer.initialize(context) to avoid a NullPointerException from class BitmapDescriptorFactory (to get the bitmap for markers). This last trick is strange, and I don't know why the Map system isn't properly initialized itself without this call, maybe it's just a bug in the current version ...

在我来说,我还没有得到任何 NullPointerException异常 onResume()的onDestroy()

In my case I haven't had any NullPointerException in onResume() or onDestroy().

阅读全文

相关推荐

最新文章