-1
我在我的应用程序片段中使用Google地图并面临一个问题。使用谷歌地图支持片段的故障状态错误
我得到这个错误
“java.lang.IllegalStateException:失败节能状态:活跃 SupportMapFragment {} 212f6b1已清除指数:-1”
我的手机去的时候在含有谷歌地图的片段处于活动状态时进入睡眠。 我的代码包含谷歌地图在这里:
public class MapFragment extends Fragment implements OnMapReadyCallback{
public MapFragment() {
}
GoogleMap mgoogleMap;
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d("cycle","Mapfragment-created");
View RootView = inflater.inflate(R.layout.mapfragment, container, false);
SupportMapFragment mapFragment = (SupportMapFragment) getChildFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
return RootView;
}
@Override
public void onMapReady(GoogleMap googleMap) {
Log.d("map", "OnMapReady");
if (mgoogleMap == null)
mgoogleMap = googleMap;
}
@Override
public void onResume() {
super.onResume();
Log.d("cycle-mapfragment","onResume");
}
@Override
public void onPause() {
super.onPause();
Log.d("cycle-mapfragment", "onPause");
}
@Override
public void onStop() {
super.onStop();
}
@Override
public void onDestroyView() {
try {
SupportMapFragment fragment = ((SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.map));
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.remove(fragment);
ft.commit();
} catch (Exception e) {
e.printStackTrace();
}
finally {
super.onDestroyView();
}
}
}
如何解决这个问题?