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 I know it won't be withdrawn. In addition, the Dialog
's content is with regards to payment confirmation, so I believe there's reasonable scope for it to be displayed without a strict relationship to a certain Window
.
Is this a safe implementation? Am I avoiding the inevitable, and should move to a more robust pattern altogether?