Call interface - Android

  • リリースバージョン: Australia
  • 更新日 2026年03月12日
  • 所要時間:3分
  • The Call interface represents a request that is prepared for processing.

    Possible processing options include:
    • cancel
    • enqueue
    • execute
    • map

    A call object cannot be processed twice.

    表 : 1. Properties
    Name Type Description
    request Request Original request that initiated this call.

    Call - cancel()

    Cancels the associated call, if possible (best effort.)

    表 : 2. Parameters
    Name Type Description
    None
    表 : 3. Returns
    Type Description
    None

    The following code example shows how to call this function.

    private var inFlightDataRequestCall: Call<*>? = null 
    fun cancelTransfer() = inFlightDataRequestCall?.cancel() 

    Call - enqueue(onSuccess: Consumer<Response<T>>, onError: Consumer<NowDataError>)

    Schedules the request to be executed as soon as the system\thread is available to execute this request.

    表 : 4. Parameters
    Name Type Description
    onSuccess Consumer​<Response<T>> Callback to execute if the call is successful. HTTP response with the body parsed to the data type specified by the T parameter.
    注:
    Consumer is a OOB Java type for asynchronous consumption of an object. In this case, the call uses generic to return a type Response<T> where T is the object type.
    onError Consumer​<NowDataError> Callback to execute if the call fails.

    NowDataError

    表 : 5. Returns
    Type Description
    None

    The following code example shows how to call this function.

    fun makeGraphQLRequest(query: String) { 
      val call = graphQLService.graphQLRequest(query) 
      call.enqueue( 
        { response -> handleResponse(response) }, 
        { nowDataError -> handleError(nowDataError) } 
      ) 
    } 

    Call - execute()

    Invokes the request immediately. Blocks until the response is processed or is in error.

    表 : 6. Parameters
    Name Type Description
    None
    表 : 7. Returns
    Type Description
    Response<T> Response data in the format defined in the T parameter.

    The following code example shows how to call this function.

    val response = apiService.data(NowAPIService.Endpoint( 
      relativePath = CASES_API, 
      requestMethod = HttpMethod.GET, 
      requireAuth = true) 
    ).execute()