After the user requests to delete a file (through a context menu), a DialogFragment is triggered to ask the user to confirm. If the user does confirm, the file is deleted by the calling Activity.
There are at least two ways for doing this.
The documentation suggests that the second option is superior, at least generally. But in this case the first approach seems perfectly robust no matter when the user has triggered a rotation (which resets both the Activity and the DialogFragment).
Is the first approach perfectly adequate, or is there a scenario other than rotation that makes the second approach better.
Both implementations can accomplish what you're trying to do, but there are certainly some differences between the two. In most cases, interfaces are not completely "necessary", you can always cast to a concrete class and call a method. The benefit interfaces provide is in decoupling. If you use an interface, the DialogFragment
is not tied to a specific Activity
. Any Activity
could implement the same interface and be used with the DialogFragment
, making that Fragment
more reusable (which is half of the point of fragments).