Reputation: 7
public class view extends View
{
public view(Context context)
{
super(context);
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(thing1, 200, 200, null);
run();
}
public void run()
{
try {
Thread.sleep(2000);
} catch(InterruptedException ex) {
Thread.currentThread().interrupt();
}
if(tester2){
thing1=BitmapFactory.decodeResource(getResources(), R.drawable.image2);
tester2=false;
invalidate();
}
else
{
thing1=BitmapFactory.decodeResource(getResources(), R.drawable.image1);
tester2=true;
invalidate();
}
}
}
This works fine but i get "application may be doing too much work" message in the log and skips a bunch of frames. How do i fix this?
Upvotes: 1
Views: 479
Reputation: 6037
Make sure you are not running your run()
method on the main thread, because that pauses the whole UI for at least 2000 milliseconds. Run that method on a separate Thread.
Upvotes: 1