SoFunction
Updated on 2025-03-11

Android development Intent jump pass list collection implementation example

introduction

  • Normal values ​​are passed between two activities on Android, such as: a single String, int... I won't say much
  • Reference articlehttps:///article/

Pass list collection

Note: List value passed by entity classes are serialized

  • Create an entity class first (for testing below)
import ;
//Don't forget to serialize Serializablepublic class DemoBean implements Serializable {
    String xm;
    int age;
    public String getXm() {
        return xm;
    }
    public void setXm(String xm) {
         = xm;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
         = age;
    }
}
  • The first activity
//Write a test method    public void ToJump(){
        List<DemoBean> list=new ArrayList<>();
        //Add 5 pieces of data to list        for (int i=0;i<5;i++){
            DemoBean demoBean=new DemoBean();
            ("Flower Flower"+i);
            (i);
            (demoBean);
        }
        Intent intent=new Intent(this,);
        ("list", (Serializable) list);
        startActivity(intent);
    }
  • The second activity page receives
 Intent intent=getIntent();
 List<DemoBean> list= (List<DemoBean>) ("list");
 ("TAG","---"+());// ()==5

Passing ArrayList collection

Passing ArrayList collection is the same as list

Note: Entity classes are serialized

  • The first activity
    public void ToJump(){
        ArrayList<DemoBean> arrayList=new ArrayList();
        for (int i=0;i<5;i++){
            DemoBean demoBean=new DemoBean();
            ("Flower Flower"+i);
            (i);
            (demoBean);
        }
        Intent intent=new Intent(this,);
        ("arrayList",arrayList);
        startActivity(intent);
    }
  • The second activity page receives
Intent intent=getIntent();
ArrayList<DemoBean> arrayList= (ArrayList<DemoBean>) ("arrayList");
("TAG","--------"+());// There are 5 data ()==5

Passing entity class

  • The first activity
public void ToJump(){
    DemoBean demoBean=new DemoBean();
    Intent intent=new Intent(this,);
    ("demoBean",demoBean);
    startActivity(intent);
}
  • The second activity page receives
Intent intent=getIntent();
DemoBean demoBean= (DemoBean) ("demoBean");
//Received an entire entity class

Pass String

  • The first activity
 Intent intent = new Intent(this,);
 //Set the pass key-value pair ("name","Flower Flower");
 //Activate Intent startActivity(intent);
  • The second activity page receives
 Intent intent = getIntent();
 //Get the passed value String name= ("name");
 //The value of name is: Huahua 

The above is the detailed content of the Android development Intent jump transfer list collection implementation example. For more information about Android Intent jump transfer list collection, please follow my other related articles!