I’m developing a game, that is running in a separate thread. Now I need to download an image from Internet. I’ve written an AsyncTask class for that, but I can’t figure out how to properly call it from my game thread? In fact, my AsyncTask is blocking, though I need to wait before the image is downloaded. If I use runOnUIThread, it does not block my thread and goes further, which doesn’t fit me at all. I’ve tried also using Looper.prepare() before running AsyncTask, but this also does have some troubles: Looper.myLooper().quit() does not seem to be working, and if I try to call the AsyncTask once again, I get an exception telling me that I’m trying to call Looper.prepare() for the second time.
How should I proceed? Thanks in advance.
I’m developing a game, that is running in a separate thread. Now I need
Share
If your background thread will block anyway, you don’t need AsyncTask and can do image loading directly in this thread. To post on UI thread afterwards you will need to have
Handlerwith looper set up. One option is to pass a handler created in UI thread. Other option is to pass some context to your background thread and doIf you need some progress updates during image loading, you can use AsyncTask and use handler created as described.