You should definitely avoid using AsyncTask
as an Inner Class in your Activity. Inner classes contain implicit strong references to their container class, so you run the risk of getting null pointers like you experienced during the Activity Lifecycle. And it does not just happen if Activity B goes on top of Activity A. It could happen if you rotate the device as well.
The problem is the Activity Lifecycle (which is why your IDE is not giving you warnings). For a configuration change (such as rotation), or in low memory situations, the Activity can be destroyed and recreated. But your AsyncTask will still be tied to the old activity.
There are a lot of threads about this:
https://stackoverflow.com/a/8550351/1856960
https://stackoverflow.com/a/16305144/1856960
You can also look into third party frameworks designed to deal with this:
https://github.com/stephanenicolas/robospice
Google around for more info too, this is hardly an exhaustive list.