A Demo app built to show off an assortment of options for handling UI or One Time Events on Android (e.g. showing a snackbar or prompting navigation)
Demonstrated Methods
- Passing an implementation of a Callback Interface from the View to the ViewModel
- Considerations
- Tight Coupling
- Requires Full Implementation
- No Guarantees of Call
- Need to Ensure Life-Cycle Aware
- Once the Event has been sent, the ViewModel records that the event has been sent without View confirmation
- Considerations
- Loose Coupling
- No Guarantee of Consumption
- Flexibility in Determining Sent
- Verbose
- The ViewModel sends the event immediately upon creation, neither the View or ViewModel tracks the event
- Considerations
- Loose Coupling
- No Guarantee of Consumption
- No Flexibility Determining Sent
- Low Effort to Implement
- The ViewModel maintains the sent event until the View notifies the ViewModel that the event has been handled
- Considerations
- Loose Coupling
- Guarantee of Consumption
- Flexibility Determining Sent
- Verbose
- The ViewModel doesn't maintain the idea of events, but instead treats everything as state, the View calls the ViewModel to notify it if state needs changed
- Considerations
- Loose Coupling
- Highly Reusable
- Guarantee of Consumption
- Verbose