I’m using the Universal Image Loader from nostra13 at https://github.com/nostra13/Android-Universal-Image-Loader. My problem is:
I have these classes
PhotoActivity extends FragmentActivity
ImageFragment extends Fragment
I initialize the imageLoader in the ImageFragment using imageLoader = ImageLoader.getInstance(); and in this fragment, I also display a few images using imageLoader.displayImage(...).
When my PhotoActivity gets stopped (onStop() is called), my ImageFragment stops as well and this should stop any image loading because I call imageLoader.stop() in the onStop() method. However, this is not the case and it gives me NullPointerException because onLoadingComplete() of ImageLoadingListener() is called afterwards, and this method calls getActivity() which is null at this point because the fragment was detached from its activity.
imageLoader.stop() should stop every loading process, no?
ImageLoader use
ExecutorServiceas pool for tasks. ImageLoader.stop() just do ExecutorService.shutdown() which has next Java docs:There is no guaranty that active tasks will be shutdown immediately after
shutdown(). Maybe using ofshutdownNow()is better option for that case (I’ll think about it), but it still can’t give you a guarantee of immediately task shutdown.So at this moment anyway you should check
getActivity(). But I’ll think about preventing firing of callbacks after ImageLoader has stopped. Maybe in the next version.