creating ingame menu in Android using addContentView
<p>I am trying to make a game for android. It is based on a 2d map, which the user can move around the screen. On the screen are several buttons, for example 'Shop'. When I user presses the button, I would like to fill the screen with a shop interface.</p>

<p>So far my approach has been as follows:</p>

<p>I have a mapView, and a map thread</p>

<ul>
<li><p><code>public class MapView extends SurfaceView implements SurfaceHolder.Callback {}</code></p></li>
<li><p><code>public class MapThread extends Thread { ... }</code></p></li>
</ul>

<p>The map thread periodically calls the <code>onDraw</code> method in MapView, which draws the map to the screen, whilst event listeners in <code>MapView</code> deal with moving the map.</p>

<p>For the shop, I have a similar setup, with a <code>ShopThread</code> and a <code>ShopView</code>. When the shop button is pressed, my idea is to stop the <code>MapThread</code>, and start the <code>ShopThread</code>. This would mean only the 'onDraw' method of <code>ShopView</code> will be called, allowing me to draw the shop interface.</p>

<p>In reponse to the button press I have the following code:
(I pass the activity between each of the views via the variable <code>topPage</code>)</p>

<pre><code>    mapThread.isRunning = false; //stop the map thread
    setVisibility(INVISIBLE);
    // add showView to the activity and start the ShopThread
    topPage.addContentView(shopView,new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                        ViewGroup.LayoutParams.FILL_PARENT) );
        shopView.startThread();
</code></pre>

<p>My problem is that the game freezes for a while when trying to access the shop. The screen just remains black and doesn't respond for around 30 seconds to a minute. I will also get the 'force close' or 'wait' error message from the OS. If I press wait, the ShopView will occasionally start working completely correctly. </p>

<p>I have narrowed it down to the run method in my <code>ShopThread</code> class. </p>

<pre><code>public void run() {
    Canvas c;
    while (isRunning){
        c = null;
        try {
            c = ShopView.getHolder().lockCanvas(null);
            synchronized (ShopView.getHolder()) {
                if(c != null)
                ShopView.onDraw(c);
            }
        } finally {
            if( c != null){
                ShopView.getHolder().unlockCanvasAndPost(c);
            }
        }
    }
}
</code></pre>

<p>The line <code>c = ShopView.getHolder().lockCanvas(null);</code> is simply returning null. I have placed Log.v statements in the other updateThreads and they appear to have all stopped. What is keeping a lock on the canvas, is there something I am missing? </p>
