That is a very good question. A toast or a dialog is usually a one time event and the best way to handle that from a ViewModel is using the SharedFlow. A SharedFlow will:

1) Emit values everytime you assign them.

2) not emit values on config changes.

3) hold an empty value.

In comparison to a StateFlow, they will not emit anything if the newly assigned literal is the same as before; they will unnecessarily remit on configuration changes; and they always need an initial value. Thus, SharedFlow is the best choice in this use case.

--

--

Nishant Aanjaney Jalan

Nishant Aanjaney Jalan

CS and Math Teacher@Schoolhouse | Android Developer | Oracle Certified Java Programmer | Musician | https://cybercoder-naj.github.io