Automatically Exit SurfaceView
<p>I have a game I'm developing for Android 2.x. When the player looses, I want to automatically exit that and go back to the previous menu of the game. This may be a simple question, but how do I do that?</p>

<p>I have a MenuActivity, which calls GameActivity, which calls the GameView (implementation of SurfaceView) where the game logic is.</p>

<p>UPDATE: No, wait, it's more complex than that. To make this game I followed the MoonLander example, which used threads.</p>

<p><strong>GameView</strong>:</p>

<pre><code>public class GameActivity extends Activity
{
GameView gameView;
GameThread gThread;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    gameView = new GameView(this);
    setContentView(gameView);

    gThread = gameView.getThread();
    gThread.doStart();
}
</code></pre>

<p>}</p>

<p><strong>GameView</strong>:</p>

<pre><code>package com.cp.balldrop;

public class GameView extends SurfaceView implements SurfaceHolder.Callback
{
    class GameThread extends Thread
    {


    public GameThread(SurfaceHolder sHolder, Context context, Handler handler)
    {
        //Code
    }

    public void doStart()
    {
        synchronized (mSurfaceHolder)
        {

        }
    }

    @Override
    public void run()
    {
        while (running)
        {
            Canvas c = null;
            try
            {
                c = mSurfaceHolder.lockCanvas(null);
                synchronized (mSurfaceHolder)
                {    
                    doDraw(c);
                }
            }
            finally
            {
                if (c != null)
                {
                    mSurfaceHolder.unlockCanvasAndPost(c);
                }
            }
        }
    }

    protected void doDraw(Canvas canvas)
    {
            //code
    }
}

/** Handle to the application context, used to e.g. fetch Drawables. */
private Context mContext;

/** Pointer to the text view to display "Paused.." etc. */
private TextView mStatusText;

/** The thread that actually draws the animation */
private GameThread gThread;

public GameView(Context context)
{
    super(context);

    // register our interest in hearing about changes to our surface
    SurfaceHolder holder = getHolder();
    holder.addCallback(this);

    // create thread only; it's started in surfaceCreated()
    gThread = new GameThread(holder, context, new Handler()
    {
        @Override
        public void handleMessage(Message m)
        {
           // mStatusText.setVisibility(m.getData().getInt("viz"));
           // mStatusText.setText(m.getData().getString("text"));
        }
    });

    setFocusable(true);
}

public GameThread getThread()
{
    return gThread;
}

public void surfaceCreated(SurfaceHolder holder)
{
    gThread.start();
}

@Override
public void surfaceDestroyed(SurfaceHolder holder)
{
    boolean retry = true;
    gThread.setRunning(false);

    while (retry)
    {
        try
        {
            gThread.join();
            retry = false;
        }
        catch (InterruptedException e)
        {
        }
    }
}
}
</code></pre>
