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

View file

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