Question

I've got a couple of Views that are updated once a second by a Timer task. They can't invalidate() themselves because "only the original thread that created a view hierarchy can touch its views".

There is a function called runOnUiThread for this, but I need an Activity to run it.

How can I solve this problem?

Edit: Is this what postInvalidate() is for? How guaranteed am I that the invalidation and update will happen soon (if the UI thread isn't busy)?

Was it helpful?

Solution

1)

Is this what postInvalidate() is for?

Yes

According to the Docs

Use this to invalidate the View from a non-UI thread.

invalidate() is for updating Views on the UI Thread

2)

How guaranteed am I that the invalidation and update will happen soon (if the UI thread isn't busy)?

Also from that same part of the docs

Cause an invalidate to happen on a subsequent cycle through the event loop

So I guess this depends on your definition of "soon". As the docs say it should happen on the next event loop

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top