Retrofit 基本使用
一、添加依赖和网络权限 添加依赖 implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' // 可选 implementation 'com.squareup.okhttp3:logging-interceptor...
一、添加依赖和网络权限 添加依赖 implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-gson:2.9.0' // 可选 implementation 'com.squareup.okhttp3:logging-interceptor...
一、是什么 Protocol Buffers,是Google公司开发的一种数据描述语言,是一种平台无关、语言无关、可扩展且类似于XML能够将结构化数据序列化,可用于数据存储、通信协议等方面。 二、为什么 更简单 数据描述文件只需原来的1/10至1/3 解析速度是原来的20倍至100倍 减少了二义性 生成了更容易在编程中使用的数据访问类且支持多种编程语言 三、支持的...
检查仓储 .git/hook 下面是否有 commit-msg 文件,如果没有可以到下面的地址下载,或者把其他同事的 commit-msg 文件拷贝到你的 .git/hook 重新 commit 即可。 https://review.cyanogenmod.org/tools/hooks/commit-msg https://gerrit-review.googlesource.com/...
一、内联拓展函数 let let 扩展函数的实际上是一个作用域函数,当你需要去定义一个变量在一个特定的作用域范围内,let函数的是一个不错的选择;let函数另一个作用就是可以避免写一些判断null的操作。 1.1 let 函数的使用的一般结构 object.let { it.todo() //在函数体内使用it替代object对象去访问其公有的属性和方法 ... } /...
Android生成文件失败:java.lang.IllegalStateException:Failed to build unique file: /storage/emulated/0/… 1.问题来源 App 调用相机拍照,中间有一些处理过程,然后将这张照片插入系统图片数据库中。 MediaStore.Images.Media.insertImage(getContentResol...
使用 viewpager2 时遇到如下错误, 使用 recyclerview 也有可能会遇到 : 2022-02-10 14:15:43.510 12151-12151/com.sharpcj.demo1 D/sharpcj_tag: onBindViewHolder ... 2022-02-10 14:15:43.548 12151-12151/com.sharpcj.demo1 D/A...
[toc] 一、Android MVVM 结构 Android 官方提供的架构图 二、添加依赖 如需在 Android 项目中使用协程,请将以下依赖项添加到应用的 build.gradle 文件中: dependencies { implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9") ...
[toc] 一、 Flow 与 Channel 的相互转换 1.1 Flow 转换为 Channel 1.1.1 ChannelFlow @InternalCoroutinesApi public abstract class ChannelFlow<T>( // upstream context @JvmField public val context: C...
[toc] 一、Flow 的基本使用 Kotlin 协程中使用挂起函数可以实现非阻塞地执行任务并将结果返回回来,但是只能返回单个计算结果。但是如果希望有多个计算结果返回回来,则可以使用 Flow。 1.1 Sequence 与 Flow 介绍 Flow 之前,先看下序列生成器: val intSequence = sequence<Int> { Thread...
[toc] 一、 Channel 基本使用 1.1 Channel 的概念 Channel 翻译过来为通道或者管道,实际上就是个队列, 是一个面向多协程之间数据传输的 BlockQueue,用于协程间通信。Channel 允许我们在不同的协程间传递数据。形象点说就是不同的协程可以往同一个管道里面写入数据或者读取数据。它是一个和 BlockingQueue 非常相似的概念。区别在于:Bloc...