package com.sheep.gamegroup.absBase;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

import com.sheep.jiuyan.samllsheep.R;

/**
 * Created by realicing on 2018/11/2.
 * realicing@sina.com
 */
public abstract class BaseContainerActivity extends BaseActivity {

    @Override
    protected int getLayoutId() {
        return R.layout.common_container;
    }

    protected Fragment fragment;

    @Override
    public void initView() {

        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        fragment = getSupportFragmentManager().findFragmentByTag("tag");
        if (fragment == null) {
            fragment = initFragment();
            transaction.add(R.id.frame_container, fragment, "tag");
            transaction.commitAllowingStateLoss();
        } else {
            transaction.replace(R.id.frame_container, fragment);
            transaction.commitAllowingStateLoss();
        }

    }

    protected abstract Fragment initFragment();
}
