android - i'm getting has leaked window that was originally added here error, please help ..dont know what to do
<p>Im getting this err. msg: " has leaked window that was originally added here ".
I have this code: </p>

<p>ball.java: </p>

<pre><code>    ...


  if(current_ball.physx.position.distance2(renderer.gPlayer.physx.position) &lt;= (graphics.SQUARE_SIZE-4)*2)

            {
                if(renderer.gSnd_GameOver!=0 &amp;&amp; renderer.bUseSound) renderer.gSndPool.play(renderer.gSnd_GameOver, 1, 1, 0, 0, 1);
                renderer.bIsGameOver = true;

                Message msg = new Message();
                msg.what = newgame.STATE_GAMEOVER;
                newgame.handler.sendMessage(msg);
                return;
            }
</code></pre>

<p>next,
in newgame.java ACTIVITY i have: </p>

<pre><code>    static DialogInterface.OnClickListener dialogClickListener = new  
    DialogInterface.OnClickListener() {

    public void onClick(DialogInterface dialog, int which)
    {
        Intent intent = null;

        switch (which){
        case DialogInterface.BUTTON_POSITIVE:

            dialog.dismiss();
            ((Activity) newgame.gNewGameContext).finish();
            intent = new Intent ( newgame.gNewGameContext , newgame.class );
            newgame.gNewGameContext.startActivity( intent );
            Log.d("redwing", "YES button ... successfuly processed, new intent starded.");

            break;

        case DialogInterface.BUTTON_NEGATIVE:


            dialog.dismiss();
            ((Activity) newgame.gNewGameContext).finish();
            Log.d("redwing", "NO button ... successfuly processed, current intent was closed.");
            break;
        }
    }        
</code></pre>

<p>and this HANDLER wich receives messages when GameOver (message is generated in ball.java as mentioned in above code) ... and instantiates a new alert dialog with this question "PlayAgain?" (note that this HANDLER exists and it's created in newgame.java) : </p>

<pre><code>    public static Handler handler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        super.handleMessage(msg);


        switch(msg.what)
        {
            case newgame.STATE_GAMEOVER:

                AlertDialog.Builder builder = new AlertDialog.Builder(newgame.gNewGameContext);
                builder.setCancelable(false);
                builder.setTitle("GaMeOvEr");
                builder.setIcon(R.drawable.ic_launcher);
                builder.setMessage("Play again ?").setPositiveButton("Yes", dialogClickListener)
                                                    .setNegativeButton("No" , dialogClickListener).show();
             break;
        }

    }  
};
</code></pre>

<p>...also "newgame.gNewGameContext" is set like this in newgame.java (in onCreate) :</p>

<pre><code>    @Override
protected void onCreate(Bundle newgameInstance) {
    // TODO Auto-generated method stub
    super.onCreate(newgameInstance);


    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN );
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    gNewGameContext = this;
    ......        
</code></pre>

<p>To review, i do this:</p>

<ol>
<li><p>when gameover=true, i send a message to the Handler.</p></li>
<li><p>the Handler receives gameover msg. and instantiates a new alert box</p></li>
<li><p>if user presses No button in this alert box i get "has leaked window that<br>
was originally added here"  Error ! :( </p></li>
</ol>

<p>Please help, i dont know how to fix this. 
Thank you !</p>
