How to avoid passing objects between activities

I suspect that I am using the wrong code design for my app. I am making a note taking app where each note is an object. In the main activity I create an empty

Notebook

object. In the

Notebook

is an empty mutableListOf of

Notes

s. Each

Note

has the context of the note. (text, date created, date updated …). When the user clicks on the “Add a note” button it jumps to the CreateNote activity.

I can think of two ways of adding that note. Either, 1. Serialize the

Notebook

object 2. Send the

Notebook

by using

 // In main activity intent.putExtra(NOTEBOOK, notebook) // In CreateNote activity val notebook = intent.getSerializableExtra(NOTEBOOK) as? Notebook

3. Add a newly created note to the notebook 4. Send back the updated notebook 5. Update the notebook in main activity.

Alternatively, I can create a new

Note

, serialize it, and send it back.

Is that the best coding style? If there was a way of storing the

Notebook

object as a shared object between activities I think that would be the best. I could then simply access that object (and potentially send an index if I want to edit a specific note). Is there a way to do that?

submitted by /u/bersnin
[link] [comments]