Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invalidate() inside of a thread android app

I'm new to programming androids but I have quite a bit of experience programming blackberries.

I created an app that has an activity class (main.java) and a view class (game.java).

Inside the view class I have some bitmaps being drawn to the screen. I created a thread and I'm moving the images around in the thread. However when I call invalidate() inside the thread it never redraws the screen.

Are you not able to invalidate() the screen from a thread? I know the thread is running and the invalidate is being called, it just never makes the changes on the screen.

like image 809
Dave Avatar asked Jan 05 '11 17:01

Dave


1 Answers

You have to use View.postInvalidate() if you call it from a non-UI thread. According to docs:

public void postInvalidate () Since: API Level 1

Cause an invalidate to happen on a subsequent cycle through the event loop. Use this to invalidate the View from a non-UI thread.

like image 57
maid450 Avatar answered Oct 14 '22 14:10

maid450