In addition I currently have two interfaces. The f...
# compose
c
In addition I currently have two interfaces. The first interface has some data, which I have to send when navigating to the next interface. But navigation seems to be unable to pass the object, is my following method correct? If not, what should be the best practice?
i
If you're passing arguments between destinations, you should be passing them through the route: https://developer.android.com/jetpack/compose/navigation#nav-with-args
For complex arguments, you should see this previous thread on what you should actually be doing (pass the ID, not the element itself): https://kotlinlang.slack.com/archives/CJLTWPH7S/p1604071569473300?thread_ts=1604053414.451400&cid=CJLTWPH7S
If you were going the other direction (returning a result), Navigation also has APIs for that: https://developer.android.com/guide/navigation/navigation-programmatic#returning_a_result
c
@Ian Lake I need to pass a
data class
, which consists of many classes nesting, what should I do?
i
As per the thread I linked to, you should not ever use arguments as the source of truth. Your repository/cache should be the source of truth. Remember there's process death and recreation, config changes, etc. that means you can't rely on those objects existing for the lifetime of your destination
c
@Ian Lake Okay, but what should I do? I open the next screen from the last screen, and I need to know some information about the last screen in the next screen. I am currently doing a simple transition animation, and I need coordinate information of some widgets in the last screen