public void decryptAsync ( final String data , final Callback callback ) { if ( callback == null ) return ; new Thread ( new Runnable ( ) { @ Override public void run ( ) { try { String decrypt = decrypt ( data ) ; if ( decrypt == null ) { callback . onError ( new Exception ( "Decrypt return null, it normally occurs when you send a null data" ) ) ; } callback . onSuccess ( decrypt ) ; } catch ( Exception e ) { callback . onError ( e ) ; } } } ) . start ( ) ; }
This is a sugar method that calls decrypt method in background it is a good idea to use this one instead the default method because decryption can take several time and with this method the process occurs in a AsyncTask other advantage is the Callback with separated methods one for success and other for the exception