'Android - handle delayed action (after requirements fulfilled)
I have a scenario where I want to perform an action after a specific set of requirements are fulfilled.
For example, imagine you have an app that allows customers to mark a restaurant as a favorite, but they need to be signed in first. When they tap the favorite view, it redirects to sign in, and when they return to the restaurant view (i.e. when sign in view is dismissed), if they are signed in (i.e. they did not cancel out/get an error) the restaurant will now be favorited.
I was able to do this with a pretty straight forward solution:
- When the favorite view is selected, check if user is signed in. If yes - > go ahead and favorite. All done! If no -> keep track that we have a pending favorite, and goto sign in flow.
- When the restaurant view is active again (after returning from sign in view), check if the pending favorite value is set, and also check the sign in state. If both look good, do the favorite action. Else do nothing.
In other projects I've used a construct similar to a "Promise" - where I'd observe/wait for the promise to be fulfilled in step 1, and then step 2 is done "automatically" when I fulfill the promise (either successfully, or via a failure/error handling mechanism), but I'm not able to find any solid examples of this pattern on Android/Kotlin.
Am I over thinking it? Does such a mechanism exist?
Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
