Hi guys. Does anyone know if we have anything new ...
# android-architecture
k
Hi guys. Does anyone know if we have anything new in Navigation Component to send data back to previous Fragment? If not then can someone please suggest me a solution for this. I am not big fan of SharedViewModel for this purpose. One solution i have in mind to observe room in previous screen and update this table from the closing screen. But this seems extra work.
w
I believe this is related: https://issuetracker.google.com/issues/79672220 If you could help and .
p
That is related yes. Also if you watch the Fragments talk at Android summit 2019, just last week. Ian Lakes mentioned this will be covered in the next major release. The major features they will be adding are: 1- Multi back stack 2- OnFragmentResult kind of API 3- Fragment Lifecycle improvements. The sad part of this, is that he mentioned it will take a "few" months. It could be 3 but also 6 🤷‍♂️ I had created a workaround a few months ago in my current company. They really wanted to use Jetpack Navigation although I opposed. I am porting it now to this project: https://github.com/pablichjenkov/Pack-Navigation I am not done yet, I need to extract some other classes that I created for bottomNavigationView. But the result delivery API is done. Basically what I have is a Global MailBoxStore ViewModel. Each Fragment send message to each other based on their mailBox ID which is the Fragment nav graph ID. Every time a Fragment starts, it checks if there is a message in its mailBox. In such a case it will start in the
onFragmentResult()
mode. Check if the concept works for you.
👏 3
👍 1
k
Thanks. I will check it out.
p
The concept is simple. Each Fragment has an ID which is used to send a message from any other Fragment. A message can be an Input Message or a Result Message. Depending on the type the Fragment will determine if starting in Input Mode or onResult Mode. If the Message is type Input it contains a field replyTo. This is used to deliver a Result Message back to the caller Fragment. I have built an App based on this concept. It will be out by the end of the year. After *Ian*'s talk I start getting ready for migration. Lets see what Google brings to the Table. To me he sounded like the solution could be an Event Bus or a Message Queue System or sort of, because he mention it will be used not just for Fragments but for any component. And is not
Intent
based, thankfully.