What you are trying to do is a really bad practice. However, I canβt tell you the information that you present to us, what is the problem. I think the ImageLoading library is already doing something in its thread, so your Thread is already finished. In addition, only the main user interface thread can access or manipulate UI views, but an exception will be thrown if this is a problem.
In addition, I would recommend you use Picasso . It handles threadpooling, scheduling, caching, memory management (avoid memory leaks with WeakReference) and revises the view in a ListView or RecyclerView.
Update:
You create Thread every time getView() is called while scrolling. This is bad practice because creating a Thread expensive. Consider dropping or scrolling through the list quickly. If you scroll through 20 items, 20 threads will be created and started. All of them have the same priority as the main user interface thread. This means that the CPU is shared between 20 threads and the main thread of the user interface. This can lead to poor user interface performance. You must use ThreadPool . In addition, you do not stop your topic. This leads to two problems:
- Your view gets recycled in
getView() , but Thread doesnβt, so the thread is still working while another view should be displayed in the view. - You get memory leaks! Do you know how the garbage collector works? It starts at the thread level and searches for unused objects (objects that no other objects refer to anymore). Your topic is an inner class. Therefore, it has a solid reference to the surrounding
Adapter class. Adapter attached to ListView , ListView to Activity . Therefore, if your activity is closed by the user, the garbage collector cannot collect Activity and all views and other objects until Thread (Thread) is complete. You probably don't have enough memory.
And last, but not least, the Android system has its own message streaming system, and only the main user interface thread can access the user interface views. I do not want to understand in detail here, I am sure that you can do this. At this point, I recommend using AsyncTask if you really need to start your own Thread. But you also have to manually cancel AsyncTask to avoid memory leaks.
source share