views:

46

answers:

1

I have an Android activity that creates custom views, and it is an expensive process. I tried to use a Handler, but when I do, the progress dialog that shows, spins like once every 5 seconds. So I tried to use an AsyncTask. Now the progressDialog spins, but then it crashes, because it isn't allowed to load the UI? How can I do this without getting ANR?

08-10 19:28:21.313: ERROR/AndroidRuntime(1428): Caused by: android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
A: 

I have an Android activity that creates custom views, and it is an expensive process.

Use Traceview or other tools to improve your performance. Custom views are not intrinsically expensive to create.

So I tried to use an AsyncTask. Now the progressDialog spins, but then it crashes, because it isn't allowed to load the UI?

You generally cannot do UI-related work in a background thread. With some care, you may be able to construct widgets, but you definitely cannot attach them to the screen (i.e., they can't be referenced as children of whatever is your content view).

How can I do this without getting ANR?

I would focus on fixing your performance problem, using Traceview or other tools to get at the root of where your time is being spent.

CommonsWare
http://quickupload.net/tqfq8ir8nv6g/add_providers-quickupload.net.trace.html I have no idea how to read this! Why can't I vertically extend the colorful part? Also, I have no idea whats important, what to look for or what to do when I've found it.
Aymon Fournier