开发者

Ways of loading bitmap/drawable to view async in android

I've got activity that has to do many things before it is visible. In proccess of loading view I have to load up bitmap/drawable that consume some time and prevents from other actions that could be done in that time. So i decide to move it to another thread. I've used Async Task, but thi开发者_如何学编程s is not solid way of loading things. There are situations where task starts 1-2 sec after my view is shown! Is there anothe way to load bitmap/drawable that will not consume so much time and will allow to assign it to ImageView?


It is likely that you are still blocking your UI thread before executing the task. Use a logger to verify when your task is being executed.

If the task does take up a lot of time to execute then the bitmaps you are loading may be too large, in which case you should look at the down-sampling the images you are loading using the inSampleSize option with BitmapFactory.


AsyncTask runs tasks from a thread pool which might already be fully in use so it might have to keep the tasks in queue until a thread frees up to run new task. Though I doubt this is the cause of the problem.

You should maybe consider displaying a progress indicator before the actual view you want to show to make sure all tasks are done before the user sees them.

Edit

you could also use task.get(); after running all the other tasks to wait for the bitmap loader to complete before showing anything... but do try to keep the UI responding!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜