当前位置:  开发笔记 > 编程语言 > 正文

失败保存状态:活动SupportMapFragment {}已清除索引:-1

如何解决《失败保存状态:活动SupportMapFragment{}已清除索引:-1》经验,为你挑选了0个好方法。

我正在使用supportMapFragment里面的片段这就是为什么我使用this.getChildFragmentManager()如果这个错误请指导我

public static ClinicFragment newInstance() {
        ClinicFragment fragment = new ClinicFragment();
        return fragment;
    }
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        setTargetFragment(null , -1); // one of my tries 
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.activity_maps, null, false);

        Log.i(TAG , "onCreateView");

        mapFragment = (SupportMapFragment) this.getChildFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
        mapUtils = new MapUtils(getActivity());
        .......
        return view;
    }


 @Override
    public void onMapReady(com.google.android.gms.maps.GoogleMap googleMap) {
        mMap = googleMap;
        mMap.setMyLocationEnabled(true);
        mMap.getUiSettings().setZoomControlsEnabled(true);
        mMap.setOnMarkerClickListener(this);
    }

@Override
public void onPause() {
    super.onPause();
    mapUtils.removeUpdate(mMap); // this helper class handle change location listener   
    Log.i(TAG, "onPause");
}
@Override
public void onDestroyView() {
    super.onDestroyView();
    Log.i(TAG, "onDestroyView");

}

@Override
public void onStop() {
    super.onStop();
    Log.i(TAG, "onStop");

    killOldMap();
}

//remove map fragment when view disappeared
private void killOldMap() {
    try{
        SupportMapFragment mapFragment = ((SupportMapFragment) getChildFragmentManager()
                .findFragmentById(R.id.map));
        if(mapFragment != null) {
            FragmentManager fM = getFragmentManager();
            fM.beginTransaction().remove(mapFragment).commit();
        }
    }catch (Exception e){
        e.printStackTrace();

    }

}

我的日志

java.lang.IllegalStateException: Failure saving state: active SupportMapFragment{1ba0fd93} has cleared index: -1
at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1824)
at android.support.v4.app.Fragment.performSaveInstanceState(Fragment.java:2111)
at android.support.v4.app.FragmentManagerImpl.saveFragmentBasicState(FragmentManager.java:1767)
at android.support.v4.app.FragmentManagerImpl.saveAllState(FragmentManager.java:1835)
at android.support.v4.app.FragmentController.saveAllState(FragmentController.java:125)
at android.support.v4.app.FragmentActivity.onSaveInstanceState(FragmentActivity.java:523)
at android.app.Activity.performSaveInstanceState(Activity.java:1297)
at android.app.Instrumentation.callActivityOnSaveInstanceState(Instrumentation.java:1272)
at android.app.ActivityThread.callCallActivityOnSaveInstanceState(ActivityThread.java:3923)
at android.app.ActivityThread.performStopActivityInner(ActivityThread.java:3334)
at android.app.ActivityThread.handleStopActivity(ActivityThread.java:3390)
at android.app.ActivityThread.access$1100(ActivityThread.java:144)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1307)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5221)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

我可以描述我的错误,它尝试删除地图片段,但他无法找到它的参考

我的尝试

1-经过长时间的研究,我发现了 setTargetFragment(null , -1);方法

在onStop中杀死2个片段.

但所有这些尝试都没有帮助我解决我的问题,任何人都可以指导我为什么我想念

推荐阅读
爱唱歌的郭少文_
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有