0

I have 30 users displayed in a LazyColumn. On user click, I navigate forward to UserDetailsScreen. My question, is it better to pass the ID of the user and create another database (Room) call inside the second screen, or is it better to pass the object as a String?

I read an answer from @ianhanniballake which says that:

Passing complex data structures over arguments is considered an anti-pattern.

As per my understanding, it's better to only send the ID of the object and not the object itself. However, I have also read, that we can convert the object into a String and pass it further to next screen. Are there any downsides in this case?

Which option is more likely to be used? Is the second one also considered an anti-pattern?

Joan P.
  • 2,368
  • 6
  • 30
  • 63
  • 2
    Passing the id is the way the maintainers implied when creating the Navigation - and ianhanniballake is one of them, so his answers are more than reliable. On the other hand, passing an object as a string is a hack, better not to do it, if you can. – Phil Dukhov May 13 '22 at 07:34
  • 1
    Thanks for your question. I'm the guy who answer the second link you posted. I added this information on my answer: "Ian Lake is an Android Developer Advocate and he says in this answer that pass an id is an anti-pattern (referring the documentation). He works on this library, so he has authority on this. Use the approach below by your own." – nglauber May 13 '22 at 14:02

0 Answers0