重复使用OfflineTileProvider会冻结应用程序

时间:2018-02-04 17:16:30

标签: osmdroid

我有一个包含MapView的片段的活动。 MapView使用OfflineTileProvider,使用CacheManager下载切片。重复进入和退出活动时,应用程序有时会冻结。有时它会在重新访问一次或两次活动后发生,有时它会在冻结之前花费更多次(20次或更多次)。

每次进入活动时,都会抛出两种异常,第一种是:

Error loading tile
                                                      java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed.
                                                          at android.database.sqlite.SQLiteConnectionPool.throwIfClosedLocked(SQLiteConnectionPool.java:962)
                                                          at android.database.sqlite.SQLiteConnectionPool.waitForConnection(SQLiteConnectionPool.java:677)
                                                          at android.database.sqlite.SQLiteConnectionPool.acquireConnection(SQLiteConnectionPool.java:348)
                                                          at android.database.sqlite.SQLiteSession.acquireConnection(SQLiteSession.java:894)
                                                          at android.database.sqlite.SQLiteSession.executeForCursorWindow(SQLiteSession.java:834)
                                                          at android.database.sqlite.SQLiteQuery.fillWindow(SQLiteQuery.java:62)
                                                          at android.database.sqlite.SQLiteCursor.fillWindow(SQLiteCursor.java:145)
                                                          at android.database.sqlite.SQLiteCursor.getCount(SQLiteCursor.java:134)
                                                          at org.osmdroid.tileprovider.modules.MapTileSqlCacheProvider$TileLoader.loadTile(MapTileSqlCacheProvider.java:209)
                                                          at org.osmdroid.tileprovider.modules.MapTileModuleProviderBase$TileLoader.run(MapTileModuleProviderBase.java:297)
                                                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                          at java.lang.Thread.run(Thread.java:760)

和第二个:

Unable to store cached tile from Mapnik /0/0/0 db is null
                                                      java.lang.NullPointerException: Attempt to invoke virtual method 'int android.database.sqlite.SQLiteDatabase.delete(java.lang.String, java.lang.String, java.lang.String[])' on a null object reference
                                                          at org.osmdroid.tileprovider.modules.SqlTileWriter.saveFile(SqlTileWriter.java:175)
                                                          at org.osmdroid.tileprovider.modules.MapTileDownloader$TileLoader.loadTile(MapTileDownloader.java:251)
                                                          at org.osmdroid.tileprovider.modules.MapTileModuleProviderBase$TileLoader.run(MapTileModuleProviderBase.java:297)
                                                          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                          at java.lang.Thread.run(Thread.java:760)

是否有其他人有过类似的问题,或者知道该怎么做?

1 个答案:

答案 0 :(得分:0)

这很有趣。看起来像生命周期/并发问题。地图片段的旧实例可能仍然存在。你可以通过强制android立即执行来解决这个问题:

来自osmdroid测试/仪器包

fm.beginTransaction().replace(org.osmdroid.R.id.samples_container, basefrag, ExtraSamplesActivity.SAMPLES_FRAGMENT_TAG) .addToBackStack(ExtraSamplesActivity.SAMPLES_FRAGMENT_TAG).commit(); fm.executePendingTransactions();

基本上,它会强制片段事务立即发生,这会迫使android生命周期事件发生。

另一种可能性是您拥有对地图的静态引用或者持有地图引用或离线切片提供程序实例的内容。有可能吗?

编辑:我刚刚在一个片段中测试了地图,通过多次加载和卸载地图而无法重现它。您是以编程方式创建地图还是使用xml布局?