亲测有效:Arouter传递对象,在activity、fragment中接收

先上接收到的对象效果(Activity中的)

亲测有效:Arouter传递对象,在activity、fragment中接收_第1张图片

 1.传递

 .withSerializable("dateBean",dateBean)

2.对象(这里只是示例,所以没有把全部的属性放出来,用…………代替了。我传递的是DataBean,所以DataBean进行Serializable)

public class LeaveListResponse {

    …………………………………………
    private List data;

    public List getData() {
        return data;
    }

    public void setData(List data) {
        this.data = data;
    }

    public static class DataBean implements Serializable {
        ………………………………
        private String LeaveId;
       
        public String getLeaveId() {
            return LeaveId;
        }

        public void setLeaveId(String LeaveId) {
            this.LeaveId = LeaveId;
        }
       
    }
}

3.activity中接收(注:此处的dateBean跟前面传递的"dateBean"一致)

 Intent intent = getIntent();
 LeaveListResponse.DataBean dateBean = (LeaveListResponse.DataBean)intent.getSerializableExtra("dateBean");

 

4.fragment接收

4.1 在fragment对应的主activity中,在切换到BFragment中添加如下代码(case 1是代表着切换到BFragment):

 Bundle bundle = new Bundle();
 bundle.putSerializable("dateBean", getIntent().getSerializableExtra("dateBean"));
 BFragment.setArguments(bundle);

亲测有效:Arouter传递对象,在activity、fragment中接收_第2张图片

4.2 fragment接收

 LeaveListResponse.DataBean dateBean= (LeaveListResponse.DataBean) getArguments().getSerializable("dateBean");

 

完成 !

你可能感兴趣的:(AS修炼手册)