Is it safe to use the ApplicationContext for a Dialog?
问题 I'm running an application that generates a dialog alert from within a Fragment as a network callback. This requires you to pass in an available Context reference; since I'm using Fragment s, I use getActivity() . Due to the network-dependent nature of the callback, getActivity() can sometimes return null. This crashes my code. To work around this error, I was hoping to supply the ApplicationContext to the dialog instead. It is a singleton that persists for the lifetime of the application, so