The example doesn't have those annotations because the class is in its own file. This means it is independent of the Activity that uses the Fragment.

In your case, your Fragment is inside an Activity and doesn't use the static modifier. This means it is tied to the Activity instance.

Having the Fragment depend on the Activity instance is a bad idea, both these classes have complex lifecyles (especially since Activities get destroyed and recreated quite often) and should be independent of each other.

You will need to make EnableGpsDialogFragment's modifier static.

public static class EnableGpsDialogFragment extends DialogFragment {

A static class does not depend on the enclosing class' instance, so the warning will go away.

Edit in response to your edit:
Now that the classes don't depend on each other's instance, you will have to get out an instance of YourActivity so you can call enabledLocationSettings() one way is by casting and will only work if EnableGpsDialogFragment is only used by YourActivity: