sunwen

Results 29 comments of sunwen

## apk package ![image](https://user-images.githubusercontent.com/10796970/58246285-3a15a780-7d89-11e9-9276-0b8c871bf64f.png) ![android_build](https://user-images.githubusercontent.com/10796970/58246789-9200de00-7d8a-11e9-8587-8443059108a5.png)

## LifeCycle ![image](https://user-images.githubusercontent.com/10796970/58308366-fe83e780-7e33-11e9-9237-799094cb0762.png)

## ViewModel ![1813550-dfc5732b031a4fd5](https://user-images.githubusercontent.com/10796970/58312435-dac59f00-7e3d-11e9-86f5-41aa8ee7096c.png)

## webview 优化 ![2362769-a8b56d5088dc393b](https://user-images.githubusercontent.com/10796970/58369757-b6e38580-7f31-11e9-8069-f0d6156c296d.png)

# Android: Multi Module Structure ![image](https://user-images.githubusercontent.com/10796970/61918917-e2144080-af85-11e9-8cd1-ffabb73ce881.png)

# Music ![music1](https://user-images.githubusercontent.com/10796970/68538618-74fcad80-03b2-11ea-93a1-8b3dcf9b4d53.png) ![music2](https://user-images.githubusercontent.com/10796970/68538620-76c67100-03b2-11ea-9134-b172cd9ae0f7.png) ![music](https://user-images.githubusercontent.com/10796970/68538621-78903480-03b2-11ea-8558-67ced2a0f815.png)

## 自定义 View ![bagua](https://user-images.githubusercontent.com/10796970/74587814-353d0600-5032-11ea-8f7e-4490e5a37eb9.gif) ![loading](https://user-images.githubusercontent.com/10796970/74587827-60275a00-5032-11ea-93e4-048abc423359.gif)

## 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...