How to pass an object from one activity to another on Android

后端 未结 30 3947
遇见更好的自我
遇见更好的自我 2020-11-21 04:03

I am trying to work on sending an object of my customer class from one Activity and display it in another Activity.

The code for t

30条回答
  •  情歌与酒
    2020-11-21 04:59

    public class MyClass implements Serializable{
        Here is your instance variable
    }
    

    Now you want to pass the object of this class in startActivity. Simply use this:

    Bundle b = new Bundle();
    b.putSerializable("name", myClassObject);
    intent.putExtras(b);
    

    This works here because MyClass implements Serializable.

提交回复
热议问题