EventBus传值

导入依赖

implementation 'org.greenrobot:eventbus:3.1.1'

传出数据,跳转

 EventBus.getDefault().postSticky(id);
 Intent intent = new Intent(context,DetailsActivity.class);
 context.startActivity(intent);

在activity中接收值


public class DetailsActivity extends AppCompatActivity implements IDateilsView {

  
    private DetailsPersenter detailsPersenter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_details);
        ButterKnife.bind(this);
        detailsPersenter = new DetailsPersenter(DetailsActivity.this);
        EventBus.getDefault().register(this);

    }

    @Subscribe(sticky = true,threadMode = ThreadMode.MAIN)
    public void eventBusReceive(String id) {
        System.out.println(id);
       
    }


     //解绑
    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }

  

 

你可能感兴趣的:(EventBus传值)