simbiose / Encryption

Encryption is a simple way to encrypt and decrypt strings on Android and Java project.
MIT License
354 stars 79 forks source link

Callback #10

Closed euniceg82 closed 8 years ago

euniceg82 commented 8 years ago

Hi, how would I use the encrypt/decrypt async in Activity? I already implemented the Encryption.Callback. What should I do next? Thanks!

ademar111190 commented 8 years ago

Hi!

To use encrypt in an Activity it is likely any other place, if the question is about thread, you can back to main thread using activity's method runOnUiThread:

  encryption.decryptAsync(encryptedText, new Encryption.Callback() {
    @Override
     public void onSuccess(String decryptedText) {
       // runOnUiThread is an activity method.
       runOnUiThread(new Runnable() {
         @Override
         public void run() {
           // Do anything in main thread
         }
       });
     }
    @Override
    public void onError(Exception exception) {}
  });

naturally you can also create your own Handler and back to any thread that you want even the UI.

euniceg82 commented 8 years ago

Got it. Hoping that it would solve the "lag/hang" in app. Thanks!

ademar111190 commented 8 years ago

You're welcome.

The encrypt/decrypt can take a while, you can adjust some parameters and/or think in a UI/UX to deal with the delay.

So I'm going to close the issue, any doubts fell free to ask.