I have an Activity. This Activity has a ListView with a BaseAdapter attached to it.
In onDestroy, the adapter is stored in a class, in onCreate it is reattached to the new Activity.
The adapter loads stuff from the internet and creates Views for the ListView.
In order to be able to start an AsyncTask (to load my data) from the adapter, it needs a LoaderManager. I pass it from the Activity to the adapter with the getSupportLoaderManager() of my Activity.
Is the following correct: as the adapter is being kept and reattached to
Activities, it will always hold a reference to the old, long goneActivitythat I first passed to it, which could / will lead to memory leaks?How can I prevent this? I thought about replacing the adapter's
LoaderManagerevery time it is reattached to a newActivitywith the newActivity'sgetSupportLoaderManager()? Is this safe / common?How can I in general find possibly dangerous references to 'old'
Activities?
Get rid of your static data member. Use a retained fragment, or
onRetainNonConfigurationInstance(), to retain the adapter across configuration changes.If by "dangerous" you mean "leaked", use MAT.