The scenario is as follows, I have a ViewPager that contains fragments, each of these fragment has some action that requires confirmation.
I proceed to create a DialogFragment targeting the fragment that knows also how to handle the result, however the fragment might be recreated before the user confirms or declines the dialog..
I could pass a lambda, or some other form of a listener to the dialog, which would then be called when user confirms dialog, but the problem is that if the device is then rotated, the lambda is lost, as it cannot be persisted on the bundle...
Only way I can think of is assign some UUID to the dialog, and connect the UUID in the application to the lambda, which is kept on Map inside the application, however this seems very sloppy solution..
I tried searching for existing solutions online, such as material-dialogs librarys sample, but most of the cases seem to dismiss the dialog on rotation, but this also seems like a sloppy solution, as the dialog might be a part of longer flow, such as
request purchase -> cancel -> show dialog with explanation -> purchase again if user wants to
where the state of flow would be lost, if we simply dismiss dialog on rotation