How can I switch to a new bitmap on touch in a Live Wallpaper?
<p>I'm trying to make a live wallpaper where it loads a certain bitmap to begin with, and then each time the user touches the screen, it will get rid of the last bitmap and load a new one.</p>

<p>My method 'run' calls to the doDraw() method:</p>

<pre><code>@Override
    public void run() {
        this.run = true;
        Canvas c = null;
        while (run) {
            try {
                c = this.surfaceHolder.lockCanvas(null);
                synchronized (this.surfaceHolder) {
                    currentTime = System.currentTimeMillis();
                    updatePhysics();
                    doDraw(c);
                    previousTime = currentTime;
                }
            } finally {
                if (c != null) {
                    this.surfaceHolder.unlockCanvasAndPost(c);
                }
            }
            // pause if no need to animate
            synchronized (this) {
                if (wait) {
                    try {
                        wait();
                    } catch (Exception e) {}
                }
            }
        }
</code></pre>

<p>Here is my doDraw() method, drawing a bitmap of an image inside my resources folder:</p>

<pre><code>private void doDraw(Canvas canvas) {
        canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), Picture1), 0, 0, null);
    }
</code></pre>

<p>Here is my onTouchEvent()</p>

<pre><code>   @Override
    public void onTouchEvent(MotionEvent event) {
        super.onTouchEvent(event);
        painting.doTouchEvent(event);
    }
</code></pre>

<p>As you can see, this calls to 'doTouchEvent()' which does the actual drawing when a user touches the screen. Here is the code for that:</p>

<pre><code>    public void doTouchEvent(MotionEvent event) {
        int action = event.getAction();

        switch(action){
        case MotionEvent.ACTION_DOWN:
            newImage();
            break;
        }
        this.wait = false;
        synchronized(this) {
            notify();
        }
    }
</code></pre>

<p>And this is what I have in my newImage() method that is called to in doTouchEvent():</p>

<pre><code>public void newImage(){
        Canvas c = new Canvas();
        c.drawBitmap(BitmapFactory.decodeResource(getResources(), Picture2), 0, 0, null);
    }
</code></pre>

<p>So I guess my main problem is trying to remove the original bitmap that was created, and apply the new bitmap when a user touches the screen.</p>
