From 711f12fa9ec23fa3be2da22e82dbb107cca9293e Mon Sep 17 00:00:00 2001 From: Andy2 Date: Thu, 25 Aug 2011 05:49:09 -0700 Subject: [PATCH] It's ok to cache listeners but only with the instance whose ivars they reference: revert prev change but make cache vars non-static. --- .../org/eehouse/android/xw4/DlgDelegate.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java index 57301c642..71f5b433a 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/DlgDelegate.java @@ -53,6 +53,10 @@ public class DlgDelegate { private static final String CALLBACK = "callback"; private static final String MSGID = "msgid"; + // Cache a couple of callback implementations that never change: + private DialogInterface.OnClickListener m_cbkOnClickLstnr = null; + private DialogInterface.OnDismissListener m_cbkOnDismissLstnr = null; + public interface DlgClickNotify { void dlgButtonClicked( int id, int button ); } @@ -317,20 +321,21 @@ public class DlgDelegate { private DialogInterface.OnClickListener mkCallbackClickListener() { - DialogInterface.OnClickListener lstnr = - new DialogInterface.OnClickListener() { + if ( null == m_cbkOnClickLstnr ) { + m_cbkOnClickLstnr = new DialogInterface.OnClickListener() { public void onClick( DialogInterface dlg, int button ) { Assert.assertTrue( 0 != m_cbckID ); m_clickCallback.dlgButtonClicked( m_cbckID, button ); } }; - return lstnr; + } + return m_cbkOnClickLstnr; } private Dialog setCallbackDismissListener( Dialog dialog ) { - DialogInterface.OnDismissListener lstnr = - new DialogInterface.OnDismissListener() { + if ( null == m_cbkOnDismissLstnr ) { + m_cbkOnDismissLstnr = new DialogInterface.OnDismissListener() { public void onDismiss( DialogInterface di ) { Assert.assertTrue( 0 != m_cbckID ); m_clickCallback.dlgButtonClicked( m_cbckID, @@ -338,7 +343,8 @@ public class DlgDelegate { m_cbckID = 0; } }; - dialog.setOnDismissListener( lstnr ); + } + dialog.setOnDismissListener( m_cbkOnDismissLstnr ); return dialog; }