Adding an interface class for custom objects

I have a custom object class, but it is implemented through inteface, how can I include passive processing in it. I followed and looked at information about resolvable, but this is only for the class of objects. for example: How can I create my custom Parcelable objects?

I want to transfer my list of objects to another activity in android.

the code:

public interface Projection { interface Job { @XBRead("./task") List<Task> getTasks(); @XBRead("./id") String getid(); @XBRead("./job_title") String getjob_title(); @XBRead("./job_description") String getjob_description(); @XBRead("./job_room") String getjob_room(); @XBRead("./status") String getstatus(); } interface Task { @XBRead("./task_id") String gettask_id(); @XBRead("./task_title") String gettask_title(); @XBRead("./task_description") String gettask_description(); @XBRead("./task_status") String gettask_status(); } @XBRead("/root/job") List<Job> getJobs(); } 
+5
source share
1 answer

For your user interfaces, extend Parcelable .

Classes that implement your own interface must also implement the Parcelable interface, including CREATOR .

Then you can add an object that implements its own interface to Intent as follows:

 intent.putExtra("thing", thing); 

or add an ArrayList containing these objects as follows:

 ArrayList<Thing> things; intent.putParcelableArrayListExtra("things", things); 

At the end of the activity, Activity can retrieve objects from the Intent as follows:

 Thing thing = intent.getParcelableExtra("thing"); 

or

 ArrayList<Thing> things = intent.getParcelableArrayListExtra("things"); 
+9
source

Source: https://habr.com/ru/post/1212893/


All Articles