Class Task<T>

java.lang.Object
com.thalesgroup.gemalto.d1.Task<T>
Type Parameters:
T - the type of result produced by this task

public abstract class Task<T> extends Object
Represents an asynchronous unit of work that produces a result of type T.

Note: Task instances should only be obtained from D1 SDK services (such as PushProvisioningService).

To execute the task:

  • Recommended: Use await() (defined in TaskExtension.kt) in Kotlin for idiomatic Kotlin async handling.
  • Use execute(D1Task.Callback) or execute() in Java to start and get the results.

Example usage in Kotlin. In this example, the task is obtained from PushProvisioningService:


 // Obtain task from PushProvisioningService

 activity.lifecycleScope.launch(Dispatchers.Main) {
      try {
          val task = pushProvisioningServiceInstance.addDigitalCardToScheme(cardID, tokenRequestor, appURL, tcsAccepted)
          val result = task.await()
          //Handle result
      } catch (e: D1Exception) {
          //Handle error
      }
 }
 
  • Constructor Details

    • Task

      public Task()
  • Method Details

    • execute

      public void execute(@NonNull D1Task.Callback<T> callback)
      Executes the task asynchronously and notifies the given callback upon completion.

      Example usage. In this example, task is a Task<String>:

      
       task.execute(new D1Task.Callback<String>() {
           @Override
           public void onSuccess(String result) {
               // Handle result
           }
           @Override
           public void onFailure(D1Exception e) {
               // Handle failure
           }
       });
       
      Parameters:
      callback - The callback to receive the result or error.
    • execute

      public abstract T execute() throws D1Exception
      Executes the task synchronously.

      Example usage. In this example, task is a Task<String>:

      
       String result = null;
       try {
            result = task.execute();
       } catch (D1Exception e) {
           //Handle error
       }
       
      Returns:
      the result of type T of the task execution
      Throws:
      D1Exception - if the task fails during execution