屏幕方向改变后活动类成员变量(Object)丢失

时间:2016-05-07 05:07:54

标签: android android-activity onconfigurationchanged

我有一个用于管理Activity内部片段的基类。它处理片段backstack,打开等但是在Orientation上更改此对象变为null并且我丢失了所有片段状态。

public class Dashboard extends AbstractNavDrawerActivity implements AsyncRequest
    .OnAsyncRequestComplete {

BaseFragmentOrganizer fragmentOrganizer;//object that manages backstack and other operation 


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
//on orientation change fragmentOrganizer becomes null so no more backstack.
    if (savedInstanceState == null) {
        fragmentOrganizer = new MainFragmentOrganizer(getSupportFragmentManager());
    }

1 个答案:

答案 0 :(得分:1)

您只需将android:configChanges="orientation|screenSize"添加到manifest文件中的活动。

它不会重新创建您的活动。