check cursor still open in attempt to fix crash seen on Galaxy Nexus

This commit is contained in:
Eric House 2012-11-01 07:59:42 -07:00
parent 3d6a170921
commit 27935752a8

View file

@ -237,26 +237,38 @@ public class SMSInviteActivity extends InviteActivity {
Phone.NUMBER, Phone.NUMBER,
Phone.TYPE }, Phone.TYPE },
null, null, null ); null, null, null );
// Have seen a crash reporting
// "android.database.StaleDataException: Attempted to access a
// cursor after it has been closed." when the query takes a
// long time to return. Be safe.
if ( null != cursor && !cursor.isClosed() ) {
if ( cursor.moveToFirst() ) { if ( cursor.moveToFirst() ) {
String name = String name =
cursor.getString( cursor.getColumnIndex( Phone.DISPLAY_NAME)); cursor.getString( cursor.
getColumnIndex( Phone.DISPLAY_NAME));
String number = String number =
cursor.getString( cursor.getColumnIndex( Phone.NUMBER ) ); cursor.getString( cursor.
getColumnIndex( Phone.NUMBER ) );
int type = cursor.getInt( cursor.getColumnIndex( Phone.TYPE ) ); int type = cursor.getInt( cursor.
getColumnIndex( Phone.TYPE ) );
m_pendingName = name; m_pendingName = name;
m_pendingNumber = number; m_pendingNumber = number;
if ( Phone.TYPE_MOBILE == type ) { if ( Phone.TYPE_MOBILE == type ) {
showConfirmThen( R.string.warn_unlimited, R.string.button_yes, showConfirmThen( R.string.warn_unlimited,
R.string.button_yes,
POST_WARNING_ACTION ); POST_WARNING_ACTION );
} else { } else {
m_immobileConfirmed = false; m_immobileConfirmed = false;
String msg = Utils.format( this, R.string.warn_nomobilef, String msg =
Utils.format( this, R.string.warn_nomobilef,
number, name ); number, name );
showConfirmThen( msg, R.string.button_yes, USE_IMMOBILE_ACTION ); showConfirmThen( msg, R.string.button_yes,
USE_IMMOBILE_ACTION );
} }
} }
cursor.close(); cursor.close();
}
} // addPhoneNumbers } // addPhoneNumbers
private void rebuildList( boolean checkIfAll ) private void rebuildList( boolean checkIfAll )