mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-08 05:24:39 +01:00
hang onto DelegateBase instance until replaced via an onStart() call.
They're often needed when the fragment isn't frontmost, i.e. when onPause() has been called. My caching instances fix is feeling a bit fragile, but I think it's better than nothing. Alternative is probably to go with DialogFragments, a big change that might not be easy to make work back to oldest Android.
This commit is contained in:
parent
7634c425ef
commit
d6b4070905
1 changed files with 14 additions and 6 deletions
|
@ -92,7 +92,6 @@ public class DelegateBase implements DlgClickNotify,
|
||||||
public void onCreateContextMenu( ContextMenu menu, View view,
|
public void onCreateContextMenu( ContextMenu menu, View view,
|
||||||
ContextMenuInfo menuInfo ) {}
|
ContextMenuInfo menuInfo ) {}
|
||||||
public boolean onContextItemSelected( MenuItem item ) { return false; }
|
public boolean onContextItemSelected( MenuItem item ) { return false; }
|
||||||
protected void onStart() {}
|
|
||||||
protected void onStop() {}
|
protected void onStop() {}
|
||||||
protected void onDestroy() {}
|
protected void onDestroy() {}
|
||||||
protected void onWindowFocusChanged( boolean hasFocus ) {}
|
protected void onWindowFocusChanged( boolean hasFocus ) {}
|
||||||
|
@ -121,10 +120,17 @@ public class DelegateBase implements DlgClickNotify,
|
||||||
getClass().getSimpleName() );
|
getClass().getSimpleName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void onStart()
|
||||||
|
{
|
||||||
|
if ( s_instances.containsKey(getClass()) ) {
|
||||||
|
DbgUtils.logdf( "%s.onStart(): replacing curThis",
|
||||||
|
getClass().getSimpleName() );
|
||||||
|
}
|
||||||
|
s_instances.put( getClass(), new WeakReference<DelegateBase>(this) );
|
||||||
|
}
|
||||||
|
|
||||||
protected void onResume()
|
protected void onResume()
|
||||||
{
|
{
|
||||||
Assert.assertFalse( s_instances.containsKey(getClass()) );
|
|
||||||
s_instances.put( getClass(), new WeakReference<DelegateBase>(this) );
|
|
||||||
m_isVisible = true;
|
m_isVisible = true;
|
||||||
XWService.setListener( this );
|
XWService.setListener( this );
|
||||||
runIfVisible();
|
runIfVisible();
|
||||||
|
@ -132,16 +138,18 @@ public class DelegateBase implements DlgClickNotify,
|
||||||
|
|
||||||
protected void onPause()
|
protected void onPause()
|
||||||
{
|
{
|
||||||
s_instances.remove( getClass() );
|
|
||||||
m_isVisible = false;
|
m_isVisible = false;
|
||||||
XWService.setListener( null );
|
XWService.setListener( null );
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DelegateBase curThis()
|
protected DelegateBase curThis()
|
||||||
{
|
{
|
||||||
|
DelegateBase result = null;
|
||||||
WeakReference<DelegateBase> ref = s_instances.get( getClass() );
|
WeakReference<DelegateBase> ref = s_instances.get( getClass() );
|
||||||
DelegateBase result = ref.get();
|
if ( null != ref ) {
|
||||||
DbgUtils.logf( "%s.curThis() => %s", this.toString(), result.toString() );
|
result = ref.get();
|
||||||
|
}
|
||||||
|
// DbgUtils.logdf( "%s.curThis() => " + result, this.toString() );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue