Skip to main content

Posts

Showing posts with the label context

Contexts, AsyncTask and rotation changes

Is it a good practice to use getApplicationContext() working with AsyncTask in order to do not have to attach and detach the Activity to avoid memory leaks when rotation changes occur and the Activity is destroyed ? I thing it should be correct, as I actually need a Context that depends on the hole application, not the Activity itself. And what is more, in those cases in which is better to use the Activity as context (because you need access to the Activity showing)... Instead of detaching it (assigning to null) when it is destroyed and then assign the new instance in onCreate() , could be just avoid detaching? So, just reasigning the new instance, this way, we could avoid problems of NullPointerException because there would always be a context to use! Thanks in advance!