release lock when BoardDelegate paused

The lock was leaking when sometimes the OS would call onStop() without
isFinishing() being true, then never use the fragment again. And never
call onDestroy(). Releasing the lock in onStop and regetting it in
onResume seems to fix, but this needs some testing and time.
This commit is contained in:
Eric House 2020-04-11 15:04:02 -07:00
parent fc30ba5f40
commit c5f1d2bf3b
2 changed files with 19 additions and 12 deletions

View file

@ -614,7 +614,10 @@ public class BoardDelegate extends DelegateBase
Log.i( TAG, "opening rowid %d", m_rowid ); Log.i( TAG, "opening rowid %d", m_rowid );
m_haveInvited = args.getBoolean( GameUtils.INVITED, false ); m_haveInvited = args.getBoolean( GameUtils.INVITED, false );
m_overNotShown = true; m_overNotShown = true;
} // init
private void getLock()
{
GameLock.getLockThen( m_rowid, 100L, new Handler(), // this doesn't unlock GameLock.getLockThen( m_rowid, 100L, new Handler(), // this doesn't unlock
new GameLock.GotLockProc() { new GameLock.GotLockProc() {
@Override @Override
@ -648,7 +651,7 @@ public class BoardDelegate extends DelegateBase
} }
} }
} ); } );
} // init } // getLock
@Override @Override
protected void onStart() protected void onStart()
@ -670,6 +673,7 @@ public class BoardDelegate extends DelegateBase
doResume( false ); doResume( false );
} else { } else {
m_resumeSkipped = true; m_resumeSkipped = true;
getLock();
} }
} }
@ -688,9 +692,11 @@ public class BoardDelegate extends DelegateBase
@Override @Override
protected void onStop() protected void onStop()
{ {
if ( isFinishing() && null != m_jniThreadRef ) { if ( null != m_jniThreadRef ) {
m_jniThreadRef.release(); m_jniThreadRef.release();
m_jniThreadRef = null; m_jniThreadRef = null;
} else {
Log.d( TAG, "onStop(): m_jniThreadRef already null" );
} }
super.onStop(); super.onStop();
} }

View file

@ -80,6 +80,7 @@ abstract class XWFragment extends Fragment implements Delegator {
protected void onCreate( DelegateBase dlgt, Bundle sis, boolean hasOptionsMenu ) protected void onCreate( DelegateBase dlgt, Bundle sis, boolean hasOptionsMenu )
{ {
Log.d( TAG, "%H/%s.onCreate() called", this, getClass().getSimpleName() );
m_hasOptionsMenu = hasOptionsMenu; m_hasOptionsMenu = hasOptionsMenu;
this.onCreate( dlgt, sis ); this.onCreate( dlgt, sis );
} }
@ -87,7 +88,7 @@ abstract class XWFragment extends Fragment implements Delegator {
@Override @Override
public void onSaveInstanceState( Bundle outState ) public void onSaveInstanceState( Bundle outState )
{ {
Log.d( TAG, "%s.onSaveInstanceState() called", getClass().getSimpleName() ); Log.d( TAG, "%H/%s.onSaveInstanceState() called", this, getClass().getSimpleName() );
Assert.assertNotNull( m_parentName ); Assert.assertNotNull( m_parentName );
outState.putString( PARENT_NAME, m_parentName ); outState.putString( PARENT_NAME, m_parentName );
outState.putInt( COMMIT_ID, m_commitID ); outState.putInt( COMMIT_ID, m_commitID );
@ -97,7 +98,7 @@ abstract class XWFragment extends Fragment implements Delegator {
protected void onCreate( DelegateBase dlgt, Bundle sis ) protected void onCreate( DelegateBase dlgt, Bundle sis )
{ {
Log.d( TAG, "%s.onCreate() called", getClass().getSimpleName() ); Log.d( TAG, "%H/%s.onCreate() called", this, getClass().getSimpleName() );
super.onCreate( sis ); super.onCreate( sis );
if ( null != sis ) { if ( null != sis ) {
m_parentName = sis.getString( PARENT_NAME ); m_parentName = sis.getString( PARENT_NAME );
@ -122,7 +123,7 @@ abstract class XWFragment extends Fragment implements Delegator {
public View onCreateView( LayoutInflater inflater, ViewGroup container, public View onCreateView( LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState ) Bundle savedInstanceState )
{ {
Log.d( TAG, "%s.onCreateView() called", getClass().getSimpleName() ); Log.d( TAG, "%H/%s.onCreateView() called", this, getClass().getSimpleName() );
sActiveFrags.add(this); sActiveFrags.add(this);
return m_dlgt.inflateView( inflater, container ); return m_dlgt.inflateView( inflater, container );
} }
@ -130,7 +131,7 @@ abstract class XWFragment extends Fragment implements Delegator {
@Override @Override
public void onActivityCreated( Bundle savedInstanceState ) public void onActivityCreated( Bundle savedInstanceState )
{ {
Log.d( TAG, "%s.onActivityCreated() called", getClass().getSimpleName() ); Log.d( TAG, "%H/%s.onActivityCreated() called", this, getClass().getSimpleName() );
m_dlgt.init( savedInstanceState ); m_dlgt.init( savedInstanceState );
super.onActivityCreated( savedInstanceState ); super.onActivityCreated( savedInstanceState );
if ( m_hasOptionsMenu ) { if ( m_hasOptionsMenu ) {
@ -141,7 +142,7 @@ abstract class XWFragment extends Fragment implements Delegator {
@Override @Override
public void onPause() public void onPause()
{ {
Log.d( TAG, "%s.onPause() called", getClass().getSimpleName() ); Log.d( TAG, "%H/%s.onPause() called", this, getClass().getSimpleName() );
m_dlgt.onPause(); m_dlgt.onPause();
super.onPause(); super.onPause();
} }
@ -149,7 +150,7 @@ abstract class XWFragment extends Fragment implements Delegator {
@Override @Override
public void onResume() public void onResume()
{ {
Log.d( TAG, "%s.onResume() called", getClass().getSimpleName() ); Log.d( TAG, "%H/%s.onResume() called", this, getClass().getSimpleName() );
super.onResume(); super.onResume();
m_dlgt.onResume(); m_dlgt.onResume();
} }
@ -157,7 +158,7 @@ abstract class XWFragment extends Fragment implements Delegator {
@Override @Override
public void onStart() public void onStart()
{ {
Log.d( TAG, "%s.onStart() called", getClass().getSimpleName() ); Log.d( TAG, "%H/%s.onStart() called", this, getClass().getSimpleName() );
super.onStart(); super.onStart();
m_dlgt.onStart(); m_dlgt.onStart();
} }
@ -165,7 +166,7 @@ abstract class XWFragment extends Fragment implements Delegator {
@Override @Override
public void onStop() public void onStop()
{ {
Log.d( TAG, "%s.onStop() called", getClass().getSimpleName() ); Log.d( TAG, "%H/%s.onStop() called", this, getClass().getSimpleName() );
m_dlgt.onStop(); m_dlgt.onStop();
super.onStop(); super.onStop();
} }
@ -173,7 +174,7 @@ abstract class XWFragment extends Fragment implements Delegator {
@Override @Override
public void onDestroy() public void onDestroy()
{ {
Log.d( TAG, "%s.onDestroy() called", getClass().getSimpleName() ); Log.d( TAG, "%H/%s.onDestroy() called", this, getClass().getSimpleName() );
m_dlgt.onDestroy(); m_dlgt.onDestroy();
sActiveFrags.remove( this ); sActiveFrags.remove( this );
super.onDestroy(); super.onDestroy();
@ -182,7 +183,7 @@ abstract class XWFragment extends Fragment implements Delegator {
@Override @Override
public void onActivityResult( int requestCode, int resultCode, Intent data ) public void onActivityResult( int requestCode, int resultCode, Intent data )
{ {
Log.d( TAG, "%s.onActivityResult() called", getClass().getSimpleName() ); Log.d( TAG, "%P/%s.onActivityResult() called", this, getClass().getSimpleName() );
m_dlgt.onActivityResult( RequestCode.values()[requestCode], m_dlgt.onActivityResult( RequestCode.values()[requestCode],
resultCode, data ); resultCode, data );
} }