0

I'm using an AsyncTask to do some task in the background (loading data from disk) for each row of a ListView. However, when I use TraceView to see how CPU is shared between my different app threads I end-up with a case where the main thread consume almost everything and around 70 thread each one consuming few CPU time. In addition none of these threads seems to complete as the rows are not redered correctely (data is not loaded).

How could I prioritize the tasks corresponding to visuale rows: complete the task for a visualize row before running (or after stopping) a task that corresponds to a hidden row.

Is there a way to do something like using a single thread and prioritizing the corresponding Runnable instances?

bachr
  • 5,780
  • 12
  • 57
  • 92
  • 2
    Is it 70 threads just in your app? 70 threads for a single app is quite a lot. Chances are there is a lot of switching between threads which also consumes time and resources. You are better off using a thread pool. Check out `ExecutorService`. Here: http://developer.android.com/reference/java/util/concurrent/ExecutorService.html – Daniel Gabriel Aug 09 '13 at 23:49
  • Using an async task for every row in a ListView seems very wrong to me, and experience tells me whatever you're doing probably has better solution available. Can you tell us more about what you're trying to do with each row? – Collin Flynn Aug 09 '13 at 23:53
  • "Is there a way to do something like using a single thread and prioritizing the corresponding Runnable instances?" -- no. The solution is to not fork 70 threads. – CommonsWare Aug 10 '13 at 00:28
  • AsyncTask uses its own ThreadPool behind the scene, and would run **every** task through a single thread on all version except 2.2 & 2.3. So you must be doing something else with your app to have 70 threads. – Kai Aug 10 '13 at 02:02
  • The ListView display a conversation where each row is a text message. However, I'm using my own fonts to display the text (check this app http://goo.gl/8bUzM). I have to load the font file (~2M bitmap file) to render the text, that's why I'm using an AsyncTask for each row (each text may be displayed with a different font). – bachr Aug 10 '13 at 10:11

0 Answers0