Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OkBus.getInstance().onEvent方法 #40

Open
FlyingWater1 opened this issue Feb 21, 2019 · 1 comment
Open

OkBus.getInstance().onEvent方法 #40

FlyingWater1 opened this issue Feb 21, 2019 · 1 comment

Comments

@FlyingWater1
Copy link

OkBus.getInstance().onEvent方法在onCreate中不起作用,在点击事件中或onResume才起作用,是否是因为界面还没有加载完成的原因?

public class Main4Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main4);
    
    //写在这里不起作用
    OkBus.getInstance().onEvent(EventTags.JUMP_TO_MAIN2);
    
    findViewById(R.id.fdfsdsfsdf).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //写在这里可以起作用

// OkBus.getInstance().onEvent(EventTags.JUMP_TO_MAIN);
}
});
}

@Override
protected void onResume() {
    super.onResume();
    //写在这里可以起作用
    OkBus.getInstance().onEvent(EventTags.JUMP_TO_MAIN2);
}

@Bus(value = EventTags.JUMP_TO_MAIN2)
public void get(){
    Log.e("Main4Activity","aaaaaaaaaaaaaaaa");
}

}

@FlyingWater1
Copy link
Author

找到原因了,是因为生成的class文件的原因,register在onEvent之后的原因,应该先register再onEvent就可以了
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(2131296292);
OkBus.getInstance().onEvent(1);
Object var3 = null;
OkBus.getInstance().register(1, (Event)this, -1);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant