看到論壇上有個網友和我一樣的問題:
The map or layer has been destroyed or recyled
I have a problem when the app restores after the map activity has been destroyed by the system.
The system calles OnDestroy on it's own, which is fine, but then, when i open the app back, everything restores (the app calles OnCreate again) except for the mapView Object.
When i try to add layers to the mapView i get the following message:
"The map or layer has been destroyed or recyled"
Does anybody had the same problem?
Any clues how to fix this?
我這邊的詳細問題是:
地圖的Activity onDestroy()後,在重新打開app的時候就報 The map or layer has been destroyed or recycled.錯誤,然後地圖能顯示
但是數據丟了..
原來的destroy()
@Override
protected void onDestroy() {
featureLayers.clear();
mMapView.destroyDrawingCache();
try {
unregisterReceiver(receiver);
}
catch (Exception e){
e.printStackTrace();
}
try {
unregisterReceiver(receiver2);
}
catch (Exception e){
e.printStackTrace();
}
//結束服務,如果想讓服務一直運行就註銷此句
try {
stopService(new Intent(this, LocationService.class));
}
catch (Exception e){
e.printStackTrace();
}
super.onDestroy();
}
//初始化數據圖層
private void initializeRoutingAndGeocoding() {
for(int i=0;i<allfloor;i++) {
Geodatabase geodatabase = null;
try {
geodatabase = new Geodatabase(geofilename[i]);
List<GeodatabaseFeatureTable> table = geodatabase.getGeodatabaseTables();
Log.i("zjx", "list:" + table);
GeodatabaseFeatureTable mytable;
if(i==1)mytable = geodatabase.getGeodatabaseFeatureTableByLayerId(0);
else mytable= geodatabase.getGeodatabaseFeatureTableByLayerId(1);
Log.i("zjx","mytable:"+mytable);
featureLayers.add(new FeatureLayer(mytable)); //問題出在這
// Attempt to load the local geocoding and routing data
mMapView.addLayer(featureLayers.get(i)); //之前的資源沒有釋放(list.clear()),get(i)並不是新增的
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
trygetDataName();
}
所以在onDestroy 裏面加一下釋放所有資源的函數,以前一直以爲java會自己快速回收的= =
,
esri論壇sso不能登錄,希望那個外國網友能看到這文章把~