retrofit

一次互联网音乐领域巨头的面试

元气小坏坏 提交于 2020-04-14 15:36:07
【推荐阅读】微服务还能火多久?>>> 前言: 最近到一家国内互联网音乐领域巨头面试,对此作记录,希望对其他人也有帮助。因为在疫情期间,所以采用远程视频面试,个人觉得相比以前方便了很多,希望以后面试也都改为远程视频面试吧哈哈。 一面: 自我介绍 最擅长什么安卓技术(我回答自定义View,这个问的不多) 自定义View主要的流程方法? onMeasure方法的参数及其意义? 测量阶段是什么遍历方式? 描述下Handler机制实现流程? Handler如何进行跨线程发送消息? ThreadLocal原理? Handler消息队列如果为空会怎么处理? Handler死循环为什么不会ANR? ANR是怎么产生的? 底层是怎么实现ANR机制的? ANR的弹出框为什么能在应用阻塞的情况下弹出? ANR的弹出框是从哪里弹出的? requestlayout调用后真正刷新视图是什么时候,简述其实现? 多次调用requestlayout会多次刷新视图界面么? 简述视图渲染的流程? 渲染同步信号是从哪里发出来的? retrofit有什么优点? retrofit用一个接口就表示一个请求的原理? 描述HashMap工作原理? HashMap怎么进行扩容? HashMap为什么扩容是以2倍扩容? 为什么Java推荐一个类如果重写了equals方法就要同时重写hashCode方法?

RxJava2+Retrofit2+RxLifecycle3+OkHttp3网络请求封装(动态演示)

感情迁移 提交于 2020-04-10 11:21:11
入职公司后,公司要求组件化开发,经过讨论后我将网络请求框架单独进行了封装,不过当时框架里将常用的 util 和 ui 均放入到了共同的 Common 包下,导致里面部分代码耦合,后来为了降低耦合性又将 Common 拆分为了lib_common和lib_ui,但是 lib_ui 依赖了 lib_common,还是导致部分代码耦合,最新一期为了降低组件之间的耦合性,所以单独将 lib_common 中的网络请求单独拆分,并且我又做了新的封装和完善,总之网络框架经过3次大的改造后,使用已经非常稳定了。 使用步骤 1.在Application类中进行初始化操作 ApiConfig build = new ApiConfig.Builder() .setBaseUrl(baseUrl)//BaseUrl,这个地方加入后项目中默认使用该url .setInvalidateToken(0)//Token失效码 .setSucceedCode(200)//成功返回码 .setFilter("com.mp5a5.quit.broadcastFilter")//失效广播Filter设置 //.setDefaultTimeout(2000)//响应时间,可以不设置,默认为2000毫秒 //.setHeads(headMap)//动态添加的header,也可以在其他地方通过ApiConfig

Retrofit源码解析二——对接口方法注解的处理

断了今生、忘了曾经 提交于 2020-04-09 09:57:20
首先通过 Utils.validateServiceInterface(service); 来检查传入的参数是否是一个没有继承关系的接口,这是怎么判断的呢? static <T> void validateServiceInterface(Class<T> service) { if (!service.isInterface()) {//1.判断是否是interface throw new IllegalArgumentException("API declarations must be interfaces."); } if (service.getInterfaces().length > 0) {//2.判断是否实现了接口 throw new IllegalArgumentException("API interfaces must not extend other interfaces."); } } 然后eagerlyValidateMethods(service)是什么鬼? private void eagerlyValidateMethods(Class<?> service) { Platform platform = Platform.get(); for (Method method : service.getDeclaredMethods()) { if

Kotlin Android Retrofit 2.6.0 with coroutines error handling

江枫思渺然 提交于 2020-04-07 18:54:59
问题 I am using Retrofit 2.6.0 with coroutines for my web service call. I am getting the API response properly with all response codes (success & error cases). My Issue is when I disconnect the internet(Wifi/mobile data) in between an API call, from the code that I have written, the error is not getting caught properly. The errors most of the time are ConnectException and SocketException. I have tried to catch the error using interceptor and also in from the ViewModel where initiated my call as

Add cookies to retrofit 2 request

半城伤御伤魂 提交于 2020-04-07 17:43:01
问题 I need to add cookies with retrofit 2.0. If i understand correct, cookies - the same as headers. this cookies must be added: private HashMap<String, String> cookies = new HashMap(); cookies.put("sessionid", "sessionId"); cookies.put("token", "token"); this one work with Jsoup lib: String json = Jsoup.connect(apiURL + "/link") .cookies(cookies) .ignoreHttpErrors(true) .ignoreContentType(true) .execute() .body(); here is my code with retrofit request: @GET("link") Call<CbGet> getData(@Header(

Add cookies to retrofit 2 request

a 夏天 提交于 2020-04-07 17:41:27
问题 I need to add cookies with retrofit 2.0. If i understand correct, cookies - the same as headers. this cookies must be added: private HashMap<String, String> cookies = new HashMap(); cookies.put("sessionid", "sessionId"); cookies.put("token", "token"); this one work with Jsoup lib: String json = Jsoup.connect(apiURL + "/link") .cookies(cookies) .ignoreHttpErrors(true) .ignoreContentType(true) .execute() .body(); here is my code with retrofit request: @GET("link") Call<CbGet> getData(@Header(

Android Retrofit 2.0 Refresh Tokens

家住魔仙堡 提交于 2020-04-07 11:04:25
问题 I am using Retrofit 2.0 with Jackson converter for communication with a Rest API. Some of the requests require tokens on authorization. If the tokens that I have are out-of-date, I need to refresh them with another request and repeat the last request that failed because of it. My question: do I need to do it manually each time or is there any way to automate it ? Here is the way I implement it at the moment: TrackerService public interface TrackerService { @POST("auth/sendPassword") Call

2019 年终总结,240+篇,已分类整理

对着背影说爱祢 提交于 2020-04-04 00:03:24
code小生 一个专注大前端领域的技术平台 以下内容按照技术模块来划分,每个大的分类下文章顺序是按照难易程序来的,这样学习起来方便些。 2017 | 我在 5 个月时间里分享了 98 篇文章 2017 下半年总结 2018 文章合集 日常开发技术 仿网易考拉 个人中心 tableView弹簧动画 Android 仿网易云鲸云音效动效 Android-图片的选择,裁剪,压缩,适配高版本 【Android】线程/进程绑定指定CPU核 Android 官方架构组件(一)——Lifecycle Android 读写锁的应用,以及最佳的磁盘缓存设计 RxJava2+Retrofit2+RxLifecycle3+OkHttp3网络请求封装 Android 官方架构组件(二)——LiveData 玩转通讯录备份(JNI实战) Android 官方架构组件(三)——ViewModel ​迟来的 2018 年总结 Android 研发技术进阶之路 ​APP上架到各大应用市场技巧 Android 框架思考--工具类设计(Glide、Picasso切换实现) ​在安卓的道路上铿锵前行 ​Android Glide缓存策略分析 ​UiStatus 一个简单且强大的 Android Ui 视图状态控制库 ​Android性能优化:关于 内存泄露 的知识都在这里了!(文不如图,图不如表) ​无懈可击

How to fix OutOfMemoryError thrown while trying to throw OutOfMemoryError with retrofit

旧巷老猫 提交于 2020-03-21 18:03:25
问题 I am using retrofit to download some media files like video,mp3, jpg, pdf,... in my application.threre is a problem when I want to download a large file with 55MB with the format of mp4. when I want to download this file I get an error like this: OutOfMemoryError threw while trying to throw OutOfMemoryError; no stack trace available this is my code: private void downloadFile() { ArrayList<FileModel> filesInDB = G.bootFileFromFileDB(); for (final FileModel fm : filesInDB) { APIService