安卓开发基类BaseActivity、BaseApplication

1、baseActivity (抽象类)

public abstract class BaseActivity extends AppCompatActivity{

    protected abstract int layoutId();

    protected abstract void initView();

    protected abstract void initData();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(layoutId());
        initView();
        initData();
    }
}

2、BaseApplication (使用单例模式)

public class BaseApplication extends Application{

    private static YNBaseApplication instance;

    public static YNBaseApplication getInstance() {
        if (instance == null){
            return new YNBaseApplication();
        }
        return instance;
    }

    @Override
    public void onCreate() {
        super.onCreate();
    }
}

你可能感兴趣的:(Android开发,工具类)