William Suh
William Suh

Reputation: 7

skipped # frames... The application may be doing too much work on its main thread.

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

Answers (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.

Upvotes: 1

Related Questions