1
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?

  • 1
    Possible duplicate of [The application may be doing too much work on its main thread](http://stackoverflow.com/questions/14678593/the-application-may-be-doing-too-much-work-on-its-main-thread) – settaratici May 12 '16 at 06:19

1 Answers1

1

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.