# NetCallback

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

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

## 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)
Content copied to clipboard
将Activity/Fragment/LifecycleOwner等作为参数传递会在其生命周期结束时自动取消网络请求.

## Functions

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

## Properties

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

## Inheritors

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