use a constant for the DISMISS button. And don't use static

listeners.  They wind up getting called with mixed DlgDelegate.this
values, including one belonging to an Activity that's long-since
stopped and so the wrong ids are getting passed back.
This commit is contained in:
Andy2 2011-08-24 22:43:54 -07:00
parent 5aeac29787
commit 3416ae59a7
3 changed files with 11 additions and 15 deletions

View file

@ -577,7 +577,7 @@ public class BoardActivity extends XWActivity
}
break;
case LAUNCH_INVITE_ACTION:
if ( -1 != which ) {
if ( DlgDelegate.DISMISS_BUTTON != which ) {
GameUtils.launchInviteActivity( BoardActivity.this,
DlgDelegate.TEXT_BTN == which,
m_room,

View file

@ -47,15 +47,12 @@ public class DlgDelegate {
public static final int TEXT_BTN = AlertDialog.BUTTON_POSITIVE;
public static final int HTML_BTN = AlertDialog.BUTTON_NEGATIVE;
public static final int DISMISS_BUTTON = 0;
private static final String MSG = "msg";
private static final String CALLBACK = "callback";
private static final String MSGID = "msgid";
// Cache a couple of callback implementations that never change:
private static DialogInterface.OnClickListener s_cbkOnClickLstnr = null;
private static DialogInterface.OnDismissListener s_cbkOnDismissLstnr = null;
public interface DlgClickNotify {
void dlgButtonClicked( int id, int button );
}
@ -320,29 +317,28 @@ public class DlgDelegate {
private DialogInterface.OnClickListener mkCallbackClickListener()
{
if ( null == s_cbkOnClickLstnr ) {
s_cbkOnClickLstnr = new DialogInterface.OnClickListener() {
DialogInterface.OnClickListener lstnr =
new DialogInterface.OnClickListener() {
public void onClick( DialogInterface dlg, int button ) {
Assert.assertTrue( 0 != m_cbckID );
m_clickCallback.dlgButtonClicked( m_cbckID, button );
}
};
}
return s_cbkOnClickLstnr;
return lstnr;
}
private Dialog setCallbackDismissListener( Dialog dialog )
{
if ( null == s_cbkOnDismissLstnr ) {
s_cbkOnDismissLstnr = new DialogInterface.OnDismissListener() {
DialogInterface.OnDismissListener lstnr =
new DialogInterface.OnDismissListener() {
public void onDismiss( DialogInterface di ) {
Assert.assertTrue( 0 != m_cbckID );
m_clickCallback.dlgButtonClicked( m_cbckID, 0 );
m_clickCallback.dlgButtonClicked( m_cbckID,
DISMISS_BUTTON );
m_cbckID = 0;
}
};
}
dialog.setOnDismissListener( s_cbkOnDismissLstnr );
dialog.setOnDismissListener( lstnr );
return dialog;
}

View file

@ -93,7 +93,7 @@ public class NewGameActivity extends XWActivity {
{
switch( id ) {
case NEW_GAME_ACTION:
if ( -1 != which ) {
if ( DlgDelegate.DISMISS_BUTTON != which ) {
makeNewGame( true, true, DlgDelegate.TEXT_BTN == which );
}
break;