Fix NPE from getActivity() call

Use onAttach and onDetach to execute mTask, to be sure that the activity
was created

Signed-off-by: Jorge Ruesga <jorge@ruesga.com>