Pass list of objects from one activity to other activity in android

后端 未结 7 1760
轻奢々
轻奢々 2020-12-01 01:35

I want to pass a list of objects from one activity from another activity. I have one class SharedBooking Below:

public class SharedBooking {         


        
7条回答
  •  自闭症患者
    2020-12-01 01:55

    You can also convert the list to a String using Gson, then pass it like so:

    String yourListAsString = new Gson().toJson(yourList);
    bundle.putString("data",yourListAsString);
    

    Then retrieve it back using your class as the type:

    List listName = new Gson().fromJson("data", new TypeToken>(){}.getType());
    

提交回复
热议问题