Code example for AsyncTaskLoader

Methods: deliverResult, onStartLoading

-1
			c = data;
 
			// If the Loader is currently started, we can immediately 
			// deliver its results. 
			if (isStarted()) {
				super.deliverResult(data);
			} 
 
			// At this point we can release the resources associated with 
			// 'oldApps' if needed; now that the new result is delivered we 
			// know that it is no longer in use. 
			if (old != null && old != c) {
				releaseResources(old);
			} 
		} 
 
		// si on a des ressources a fermer 
		protected void releaseResources(Cursor cfc) {
			Log.d("async", "should releasing cursor");
			if (c != null && !c.isClosed())
				c.close();
		} 
 
		@Override 
		public Cursor loadInBackground() {
			// synchronized (this) { 
			// if (isLoadInBackgroundCanceled()) { 
			// throw new OperationCanceledException(); 
			// } 
			// mCancellationSignal = new CancellationSignal(); 
			// } 
			// try { 
 
			// count total 
			Log.d("asyncloader", "load in background");
 
			// le query devrait etre passe en parametre... 
			String query = "select "+DBHelper.C_C_ID+","
					+DBHelper.C_TITRE+"," 
					+DBHelper.C_DATE+"," 
					+DBHelper.C_HEURE_DEBUT+"," 
					+DBHelper.C_HEURE_FIN+"," 
					+DBHelper.C_DESCRIPTION+"," 
					+DBHelper.C_IMAGE 
					+" from " + DBHelper.TABLE_E + " where _id=" + id;
 
			Cursor c = db.rawQuery(query, null);
 
			if (c != null) {
				// Ensure the cursor window is filled 
				c.getCount();
				registerContentObserver(c, mObserver);
			} 
 
			return c;
			// } finally { 
			// synchronized (this) { 
			// mCancellationSignal = null; 
			// } 
			// } 
		} 
 
		/** 
		 * Registers an observer to get notifications from the content provider 
		 * when the cursor needs to be refreshed. 
		 */ 
		void registerContentObserver(Cursor cursor, ContentObserver observer) {
			cursor.registerContentObserver(mObserver);
		} 
 
		@Override 
		protected void onStartLoading() { 
			// TODO Auto-generated method stub 
			super.onStartLoading(); 
			//setProgressBarIndeterminateVisibility(true); 
 
			Log.d("async", "on start loading");
			if (c != null) {
				deliverResult(c); // already available!