public void delete ( final T object , final SuccessCallback < Boolean > successCallback , final ErrorCallback errorCallback ) { checkNotNull ( successCallback ) ; checkNotNull ( errorCallback ) ; checkNotNull ( object ) ; final Callable < Boolean > call = new Callable < Boolean > ( ) { @ Override public Boolean call ( ) throws Exception { return SugarRecord . delete ( object ) ; } } ; final Future < Boolean > future = doInBackground ( call ) ; Boolean isDeleted ; try { isDeleted = future . get ( ) ; if ( null == isDeleted || ! isDeleted ) { errorCallback . onError ( new Exception ( "Error when performing delete of " + object . toString ( ) ) ) ; } else { successCallback . onSuccess ( isDeleted ) ; } } catch ( Exception e ) { errorCallback . onError ( e ) ; } }
This method works on top of SugarRecord and provides asynchronous code execution via the usage of Futures and callbacks to handle success result and error .