自定义片段的子类是否调用其超类的saveInstanceState方法?

时间:2018-02-20 14:07:39

标签: android android-fragments superclass

所以我有一个扩展片段

的类
public class General_Fragment extends Fragment{

    int i;

    @Override
    public void onSaveInstanceState(@NonNull Bundle outState) {
        outState.putInt(INTEGER_KEY, getInt());
        super.onSaveInstanceState(outState);
    }

    public int getInt(){
        return i;
    }

    …
}

另一个扩展这个第一堂课的课程。

public class Specific_Fragment extends General_Fragment{
    int j;

    @Override
    public int getInt(){
        return j;
    }

    …
}

当特定片段被销毁时,应该调用General_Fragments onSavedInstanceState是否正确?或者我需要在子类中实现一些东西来调用超类方法吗?

2 个答案:

答案 0 :(得分:0)

如果您未覆盖onSaveInstanceState中的Specific_Fragment方法,则会调用General_Fragment中实施的方法。

因此,只要您不需要保存来自最派生片段的其他内容,就无需覆盖它。

答案 1 :(得分:0)

不,你不需要覆盖它来调用它,它继承自它的父类General_Fragment