sunwen
sunwen
## apk package  
## LifeCycle 
## ViewModel 
## webview 优化 
# Android: Multi Module Structure 
# Music   
## 自定义 View  
## ViewModel 用于多Activity 共享数据 一般来说,一个 Activity 对应于一个 ViewModel。但有一些全局情况,比如用户退出登录,多个页面需要被通知,可以借助 ViewModelProvider.Factory 创建共享的 ViewModel 来通信和同步数据。 ``` object SharedViewModelFactory : ViewModelProvider.Factory { val viewModelMap = hashMapOf() @Suppress("UNCHECKED_CAST") override fun create(modelClass: Class): T { val...
## Gson 和 kotlin 处理服务器返回数据的几个问题 遵循两端相互不信任的原则,客户端定义的服务器返回数据接口要 Any? (可空)的。 基本数据类型可以不为空,但 String,对象类型必须要可以空,防止出现空指针错误。 对于 String,但服务器返回空时,可以使用下列方法来返回 “”。 ``` private static class StringTypeAdapter implements JsonDeserializer { @Override public String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)...
## Retrofit2 + Coroutine 使用的几个问题 1. 一般服务器返回的数据都有固定的格式。在使用中异步执行可以处理错误。但在协程下使用,只会得到返回结果,没有 rxjava2 或则异步的错误分支处理。 解决方法:可定义 okhttp 的拦截器,对 chain.process() 进行处理,将异常结果转换为 code = 200 的满足需要的服务器数据。 2. 测试 使用 runBlocking{} 进行测试,但不可用在 Android 程序中。 ``` class Retrofit_Test { val...