additional protection against fragment already being detached
refactored to prevent possible NPE in checkAppDir