I am using Fragments which contain MapViews in their xml layouts of different screen dimension according to my app's design.
Only the MapView is working for the fragment which is loaded first. Other Fragment's MapViews (when initiated) are just showing the blocked reflection of initiated MapView (of firstly loaded fragment) but its basemap layer is working in the area of actionbar. And when I get my app's resume state back after having its pause the MapView of the other fragment (top fragment of back stack) is working fine as it should be.
Tried alot to come over this issue but still having it, can you/anybody please help me out?
It will be more than appreciated.
<com.esri.android.map.MapView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mInflater = inflater;
if (savedInstanceState != null) {
mMapState = savedInstanceState.getString(KEY_MAP_STATE, null);
}
// Create new MapView object. Note that, unlike Layers objects, the MapView can't be retained when the Activity is
// destroyed and recreated, because the old MapView is tied to the old Activity.
mView = inflater.inflate(R.layout.fragment_map, container, false);
initViews(mView);
// Create layers unless retained objects are available
if(mBaseMapDynamicLayer == null) {
mBaseMapDynamicLayer = new ArcGISDynamicMapServiceLayer(AppConstants.server_url_service_mapserver);
mMapView.addLayer(mBaseMapDynamicLayer);
}
// Restore map state (center and resolution) if a previously saved state is available, otherwise set initial extent
if (mMapState != null) {
mMapView.restoreState(mMapState);
}
mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {
@Override
public void onStatusChanged(Object o, STATUS status) {
AppUtils.mMapState = mMapView.retainState();
}
});
return mView;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Save the map state (map center and resolution).
if (mMapState != null) {
outState.putString(KEY_MAP_STATE, mMapState);
}
}
private void initViews(View view) {
mMapView = (MapView) view.findViewById(R.id.map);
}
public void onResume() {
super.onResume();
// Start the MapView running again
if(mMapView != null) {
mMapView.unpause();
}
}
public void onPause() {
super.onPause();
if(mMapView != null) {
mMapState = mMapView.retainState();
mMapView.pause();
}
}
@Override
public void onDestroyView() {
super.onDestroyView();
// Must remove our layers from MapView before calling recycle(), or we won't be able to reuse them
if(mBaseMapDynamicLayer!= null && mMapView != null)
mMapView.removeLayer(mBaseMapDynamicLayer);
// Release MapView resources
if(mMapView != null) {
mMapView.recycle();
}
mMapView = null;
}
<com.esri.android.map.MapView
android:id="@+id/map_poi_details"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="10dp"
android:layout_below="@+id/tv_poi_details_phone"/>
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Reinstate saved instance state (if any)
if (savedInstanceState != null) {
mMapState = savedInstanceState.getString(KEY_MAP_STATE, null);
}
// Create new MapView object. Note that, unlike Layers objects, the MapView can't be retained when the Activity is
// destroyed and recreated, because the old MapView is tied to the old Activity.
view = inflater.inflate(R.layout.fragment_poi_details, container, false);
mMapView = (MapView) view.findViewById(R.id.map_poi_details);
// Restore map state (center and resolution) if a previously saved state is available, otherwise set initial extent
if (mMapState != null)
mMapView.restoreState(mMapState);
//else
//mMapView.restoreState(AppUtils.mMapState);
// Create layers unless retained objects are available
if(mBaseMapDynamicLayer == null) {
mBaseMapDynamicLayer = new ArcGISDynamicMapServiceLayer(AppConstants.server_url_service_mapserver);
mMapView.addLayer(mBaseMapDynamicLayer);
}
return view;
}
@Override
public void onDestroyView() {
super.onDestroyView();
// Must remove our layers from MapView before calling recycle(), or we won't be able to reuse them
mMapView.removeLayer(mBaseMapDynamicLayer);
// Release MapView resources
mMapView.recycle();
mMapView = null;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
// Save the map state (map center and resolution).
if (mMapState != null) {
outState.putString(KEY_MAP_STATE, mMapState);
}
}
public void onResume() {
super.onResume();
mMapView.unpause();
}
public void onPause() {
super.onPause();
mMapState = mMapView.retainState();
mMapView.pause();
}
FirstFragment (First screen which is working fine)
FragmentTwo (On scroll it is showing blocked reflection of FirstFragment's MapView )
FragmentTwo (In action bar area it is giving its basemap layer with scrolling motion when we scroll FragmentTwo Up and down and also this layer is working fine as FragmentTwo's mapview should be)
FragmentTwo (After pausing application and resume again to FragmentTwo the mapview is working fine as it should be)
Here's Logcat details when loading FragmentTwo:
09-18 11:25:30.479 1310-1310/myapp.arcgismap W/SurfaceView﹕ CHECK surface infomation creating=false formatChanged=false sizeChanged=false visible=false visibleChanged=true surfaceChanged=true realSizeChanged=false redrawNeeded=false left=false top=false
--------- beginning of /dev/log/system
09-18 11:25:32.999 1310-1310/myapp.arcgismap W/ApplicationContext﹕ Unable to create external cache directory
09-18 11:25:33.069 1310-1310/myapp.arcgismap D/AbsListView﹕ Get MotionRecognitionManager
09-18 11:25:33.349 1310-16948/myapp.arcgismap E/copybit﹕ Error opening frame buffer errno=13 (Permission denied)
09-18 11:25:33.349 1310-16948/myapp.arcgismap W/Adreno200-EGLSUB﹕ <updater_create_surface_state:342>: updater_create_surface_state failed to open copybit, error: -13
09-18 11:25:33.549 1310-1312/myapp.arcgismap D/dalvikvm﹕ GC_CONCURRENT freed 5137K, 39% free 18443K/30151K, paused 12ms+30ms, total 131ms
09-18 11:25:33.549 1310-1310/myapp.arcgismap D/dalvikvm﹕ WAIT_FOR_CONCURRENT_GC blocked 73ms
09-18 11:25:33.549 1310-1319/myapp.arcgismap D/AbsListView﹕ [unregisterDoubleTapMotionListener]
09-18 11:25:33.549 1310-1319/myapp.arcgismap I/MotionRecognitionManager﹕ .unregisterListener : / listener count = 0->0,
09-18 11:25:33.579 1310-1319/myapp.arcgismap D/AbsListView﹕ [unregisterDoubleTapMotionListener]
09-18 11:25:33.579 1310-1319/myapp.arcgismap I/MotionRecognitionManager﹕ .unregisterListener : / listener count = 0->0,
Shelly Gill Joshua GieseRamchand RaoScott DabbsSteve Vu