从Retrofit的原理来看HTTP
Posted on
|
In
Android
Retrofit使用方法简介
创建一个interface作为Web Service的请求集合,在里面用注解(Annotation)写入需要配置的请求方法
1
2
3
4public interface GitHubService{
@GET("users/{user}/repos")
Call<List<Repo>> listRepos(@Path("user") String user);
}在正式代码里用
Retrofit
创建出interface
的实例1
2
3
4Retrofit retrofit = new Retrofit.Builder()
.baseUrl("https://api.github.com/")
.build();
GitHubService service = retrofit.create(GitHubService.class);调用创建出的
Service
实例的对应方法,创建出相应的可以用来发起网络请求的Call
对象1
Call<List<Repo>> repos = service.listRepos("octocat");
使用
Call.execute()
或者Call.enqueue()
来发起请求1
repos.enqueue(callback);
Retrofit
源码结构总结
源码-ComponentActivity的LifecycleOwner
Posted on
|
In
Android
原文:https://weread.qq.com/web/reader/d82322e0813ab6e2eg015684
起因:使用Dialog未dismiss时Activity关闭了,导致内存泄露
解决:给Dialog添加生命周期监听
1 | class TipDialog(context: Context) : Dialog(context), LifecycleObserver { |
Gradle配置文件拆解
Posted on
|
In
Gradle
工具-Bean检查
Posted on
|
In
Android代码片段
Java-注解
Posted on
|
In
Java
Java 注解(Annotation) | 菜鸟教程 (runoob.com)
Java注解(Annotation)又称Java标注,可以通过反射获取标注内容。在编译器生成类文件时,标注可以被嵌入到字节码中。JVM可以保留标注内容,在运行时可以获取到标注内容。
支持自定义Java标注。
优雅写法
Posted on
|
In
Android代码片段
工具类
优雅关闭流
1 | import java.io.Closeable; |
安卓题目-基础面试题
Posted on
|
In
安卓