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


object. In the


is an empty mutableListOf of


s. Each


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


object 2. Send the


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


, serialize it, and send it back.

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


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]