Transferring object data from one activity to another activity

前端 未结 5 1243
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-07 08:30

I am having a class EmployeeInfo as the following:

 public class EmployeeInfo {
        private int id; // Employee ID
        private String name; // Employ         


        
5条回答
  •  迷失自我
    2021-01-07 08:34

    You can simply let your EmployeeInfo class implement Serializable. Or you can send data like this

    intent.putExtra("id", employInfo.getEmployeeID());
    intent.putExtra("name", employInfo.getEmployeeName());
    intent.putExtra("age", employInfo.getAge());
    

    If you need to transfer a list of your custom classes, i'd use the first approach. So you would be able to put entire list as Serializable.
    However they said that everyone should use Parcelable instead because it's "way faster". Tbh, I'd never used it, because it needs more effort and I doubt somebody can realize the difference in speed in a regular application w/o a load of data sending via intent

提交回复
热议问题