Do you stop/cancel your AsyncTask
if your app goes to background or is paused?
Consider the following scenario: your AsyncTask is executed, and when prompted with the progress bar, the user decides to do other stuff while she waits for the task to complete. She does so by pressing the home button. Alas, this might destroy the fragment and the activity. The running AsyncTask
knows nothing about it, and when done, getActivity()
method invocations (or local variables pointing to a non-existent Activity) may as well return null
, causing your app to crash.