Activity与Fragment
首先需要明确的是,Activity与Fragment是多对多关系。一个Activity中可以有多个Fragment,一个Fragment也可以存在于多个Activity中。
Activity向Fragment传递数据
跟Activity之间的互传数据一样需要通过Bundle对象作为载体进行传递。
- Fragment可以通过有参构造函数的参数接收Activity传来的数据。
public AFragment(String s) {
Bundle bundle = new Bundle();
//键值对
bundle.putString("name", s);
this