JessYanCoding / MVPArms

⚔️ A common architecture for Android applications developing based on MVP, integrates many open source projects, to make your developing quicker and easier (一个整合了大量主流开源项目高度可配置化的 Android MVP 快速集成框架).
Apache License 2.0
10.29k stars 2.39k forks source link

EventBus初始化过早的问题 #360

Open franticn opened 4 years ago

franticn commented 4 years ago

Related Code:

由于项目在ActivityDelegateImpl#OnCreate进行EventBus的注册,但是如果发送了粘性事件,并在接受事件的方法中对UI进行了操作 由于注册事件发生在setContentView之前,会导致找不到控件的问题

@Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        if (iActivity.useEventBus()) {
            //注册到事件主线
            EventBusManager.getInstance().register(mActivity);
        }
    }
  @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        try {
            int layoutResID = initView(savedInstanceState)
            if (layoutResID != 0) {
                //初始化布局
                setContentView(layoutResID);
            }
        } catch (Exception e) {
            if (e instanceof InflateException) {
                throw e;
            }
            e.printStackTrace();
        }
        initData(savedInstanceState);
    }