use of android.database.StaleDataException in project Talon-for-Twitter by klinker24.
the class HomeFragment method markReadForLoad.
public void markReadForLoad() {
try {
final Cursor cursor = cursorAdapter.getCursor();
final int current = listView.getFirstVisiblePosition();
if (cursor.isClosed()) {
return;
}
HomeDataSource.getInstance(context).markAllRead(currentAccount);
if (cursor.moveToPosition(cursor.getCount() - current)) {
Log.v("talon_marking_read", cursor.getLong(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_TWEET_ID)) + "");
final long id = cursor.getLong(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_TWEET_ID));
sharedPrefs.edit().putLong("current_position_" + currentAccount, id).commit();
new Thread(new Runnable() {
@Override
public void run() {
markRead(currentAccount, context, id);
}
}).start();
} else {
if (cursor.moveToLast()) {
final long id = cursor.getLong(cursor.getColumnIndex(HomeSQLiteHelper.COLUMN_TWEET_ID));
sharedPrefs.edit().putLong("current_position_" + currentAccount, id).commit();
new Thread(new Runnable() {
@Override
public void run() {
markRead(currentAccount, context, id);
}
}).start();
}
}
} catch (IllegalStateException e) {
// Home datasource is not open, so we manually close it to null out values and reset it
e.printStackTrace();
try {
HomeDataSource.dataSource = null;
} catch (Exception x) {
}
} catch (NullPointerException e) {
e.printStackTrace();
// the cursoradapter is null
} catch (StaleDataException e) {
e.printStackTrace();
// do nothing here i guess
}
}
Aggregations