NetCallback

abstract class NetCallback<T>(lifecycle: LifecycleOwner?, lifeEvent: Lifecycle.Event) : Callback

提供泛型转换特性 相对于OkHttp的Callback新增三个回调函数: onSuccessonComplete 这三个函数都运行在主线程上

Parameters

lifecycle

将Activity/Fragment/LifecycleOwner等作为参数传递会在其生命周期结束时自动取消网络请求. 避免内存泄漏

lifeEvent

指定自动取消的生命周期. 默认为Lifecycle.Event.ON_DESTROY

Constructors

NetCallback
Link copied to clipboard
fun NetCallback(lifecycle: LifecycleOwner? = null, lifeEvent: Lifecycle.Event = Lifecycle.Event.ON_DESTROY)
将Activity/Fragment/LifecycleOwner等作为参数传递会在其生命周期结束时自动取消网络请求.

Functions

onComplete
Link copied to clipboard
open fun onComplete(call: Call, e: Throwable?)
网络请求完成, 无论错误还是正常结束
onError
Link copied to clipboard
open fun onError(call: Call, e: IOException)
网络请求错误
onFailure
Link copied to clipboard
open override fun onFailure(call: Call, e: IOException)
网络请求错误, 异步线程
onResponse
Link copied to clipboard
open override fun onResponse(call: Call, response: Response)
onStart
Link copied to clipboard
open fun onStart(request: Request)
网络请求开始
onSuccess
Link copied to clipboard
abstract fun onSuccess(call: Call, result: T)
网络请求成功

Properties

lifecycle
Link copied to clipboard
val lifecycle: LifecycleOwner? = null
将Activity/Fragment/LifecycleOwner等作为参数传递会在其生命周期结束时自动取消网络请求.
lifeEvent
Link copied to clipboard
val lifeEvent: Lifecycle.Event
指定自动取消的生命周期.
request
Link copied to clipboard
lateinit var request: Request

Inheritors

DialogCallback
Link copied to clipboard
PageCallback
Link copied to clipboard
StateCallback
Link copied to clipboard