Source:
private void readGeoPackage() { mLayersHashMap = new HashMap<>(); GeoPackage geoPackage = new GeoPackage( Environment.getExternalStorageDirectory() + getString(R.string.geopackage_path)); geoPackage.loadAsync(); geoPackage.addDoneLoadingListener(() -> { if (geoPackage.getLoadStatus() == LoadStatus.FAILED_TO_LOAD) { String error = "Geopackage failed to load: " + geoPackage.getLoadError(); Log.e(TAG, error); Toast.makeText(MainActivity.this, error, Toast.LENGTH_LONG).show(); return; } for (GeoPackageRaster geoPackageRaster : geoPackage.getGeoPackageRasters()) { RasterLayer rasterLayer = new RasterLayer(geoPackageRaster); rasterLayer.setOpacity(0.55f); rasterLayer.loadAsync(); rasterLayer.addDoneLoadingListener(() -> { String rasterLayerName; String path = geoPackageRaster.getPath(); if (!rasterLayer.getName().equals("")) { rasterLayerName = rasterLayer.getName(); } else { rasterLayerName = path.substring(path.lastIndexOf("/") + 1); } rasterLayerName += "\n(RasterLayer)"; mLayersHashMap.put(rasterLayerName, rasterLayer); mLayersStringAdaptor.add(rasterLayerName); mLayersStringAdaptor.notifyDataSetChanged(); }); } List<GeoPackageFeatureTable> geoPackageFeatureTables = geoPackage.getGeoPackageFeatureTables(); for (GeoPackageFeatureTable geoPackageFeatureTable : geoPackageFeatureTables) { FeatureLayer featureLayer = new FeatureLayer(geoPackageFeatureTable); featureLayer.loadAsync(); featureLayer.addDoneLoadingListener(() -> { String featureLayerName = featureLayer.getName(); featureLayerName += "\n(FeatureLayer)"; mLayersHashMap.put(featureLayerName, featureLayer); mLayersStringAdaptor.add(featureLayerName); mLayersStringAdaptor.notifyDataSetChanged(); mDrawerLayout.openDrawer(Gravity.START); }); } }); }

Target:
private void readGeoPackage() { mLayersHashMap = new HashMap<>(); GeoPackage geoPackage = new GeoPackage( Environment.getExternalStorageDirectory() + getString(R.string.geopackage_path)); geoPackage.loadAsync(); geoPackage.addDoneLoadingListener(() -> { if (geoPackage.getLoadStatus() == LoadStatus.FAILED_TO_LOAD) { String error = "Geopackage failed to load: " + geoPackage.getLoadError(); Log.e(TAG, error); Toast.makeText(this, error, Toast.LENGTH_LONG).show(); return; } for (GeoPackageRaster geoPackageRaster : geoPackage.getGeoPackageRasters()) { RasterLayer rasterLayer = new RasterLayer(geoPackageRaster); rasterLayer.setOpacity(0.55f); rasterLayer.loadAsync(); rasterLayer.addDoneLoadingListener(() -> { String rasterLayerName; String path = geoPackageRaster.getPath(); rasterLayerName = rasterLayer.getName().isEmpty() ? path.substring(path.lastIndexOf('/') + 1) : rasterLayer.getName(); rasterLayerName += "\n(RasterLayer)"; mLayersHashMap.put(rasterLayerName, rasterLayer); mLayersStringAdaptor.add(rasterLayerName); mLayersStringAdaptor.notifyDataSetChanged(); }); } List<GeoPackageFeatureTable> geoPackageFeatureTables = geoPackage.getGeoPackageFeatureTables(); for (GeoPackageFeatureTable geoPackageFeatureTable : geoPackageFeatureTables) { FeatureLayer featureLayer = new FeatureLayer(geoPackageFeatureTable); featureLayer.loadAsync(); featureLayer.addDoneLoadingListener(() -> { String featureLayerName = featureLayer.getName(); featureLayerName += "\n(FeatureLayer)"; mLayersHashMap.put(featureLayerName, featureLayer); mLayersStringAdaptor.add(featureLayerName); mLayersStringAdaptor.notifyDataSetChanged(); }); } mDrawerLayout.openDrawer(Gravity.START); }); }