Calling getActivity() inside an AsyncTask safely
<p>My app keeps crashing when I leave it running in the background and then go back to having the app on screen. I believe it has something to do with my AsyncTask that is running in onResume(). In this <a href="https://stackoverflow.com/a/17829562/3851567">answer</a> on one of the comments the guy says to "keep trace of an instance of the activity and make the async task wait for it to be not null." So how exactly do I make it wait until it's not null? </p>

<p>And in general, what is the safest way to refer to an activity when you have an AsyncTask running inside a Fragment that will work during activity/fragment lifecycle changes?</p>