jeudi 16 juillet 2020

Update a list passed from another activity

In my application I have one screen for Admin to enter a school ID (Activity A)

Once Admin clicks on next I will be calling an API to return a list of students in that school say the name of the list is List<Student> studentsList.

The studentsList will be passed in intent to new activity (Activity B). Activity B will has a recycle view. Each item will display the name of the student and his age and button named Details

Once Details button is clicked , new Activity (Activity C) will be opened and it has a recycle view to show the list of subjects for that student along with delete button to delete the subject.

List of subjects is part of the student object which will be passed also from Activity B to Activity C via intent.

Intent intent = new Intent (ActivityB.this , ActivityC.class);
intent.putParcelable(STUDENT_OBG ,studentsList.get(position) );
startActivityForResult(intent, LAUNCH_UPDATE_SUBJECT_DETAILS);

Now when admin clicks on delete I will call an API to delete it , then i will call the same API in Activity A to get the updated list.

What I want is when admin clicks on delete and I'm calling the updated API I want to update my original list by setting it to the new returned list

studentsList = getStuList()

But I found out that when passing objects via intent we are not passing the reference , so by that the original list won't get updated.

How can I solve this issue? what is the suitable design pattern for it?

Aucun commentaire:

Enregistrer un commentaire