Back to project page BBC-News-Reader.
The source code is released under:
Copyright (c) 2011, 2012, Digital Lizard (Oscar Key, Thomas Boby) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the...
If you think the Android project BBC-News-Reader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.digitallizard.bbcnewsreader.data; // w ww. ja v a 2 s . c o m import android.content.ContentResolver; import android.database.Cursor; import android.net.Uri; public class ItemClearer implements Runnable { volatile boolean isClearing; Thread thread; ContentResolver contentResolver; long threshold; public void clearItems(ContentResolver contentResolver, long threshold) { // only allow clearing if the thread isn't running if (!isClearing) { this.isClearing = true; this.contentResolver = contentResolver; this.threshold = threshold; thread = new Thread(this); thread.start(); } } public void run() { // FIXME Optimise, should use a join // find items older than the threshold Uri uri = DatabaseProvider.CONTENT_URI_ITEMS; String[] projection = { DatabaseHelper.COLUMN_ITEM_ID }; String selection = DatabaseHelper.COLUMN_ITEM_PUBDATE + "<?"; String[] selectionArgs = { Long.toString(threshold) }; Cursor cursor = contentResolver.query(uri, projection, selection, selectionArgs, null); // find the column indexes int id = cursor.getColumnIndex(DatabaseHelper.COLUMN_ITEM_ID); // loop through and delete the items while (cursor.moveToNext()) { Uri tempUri = Uri.withAppendedPath(DatabaseProvider.CONTENT_URI_ITEMS, Integer.toString(cursor.getInt(id))); contentResolver.delete(tempUri, null, null); } cursor.close(); // mark the clearing as finished isClearing = false; } public ItemClearer() { isClearing = false; thread = null; contentResolver = null; threshold = 0; } }