简体   繁体   English

如何访问在Android应用程序中具有较高响应时间的API?

[英]How to access an API which is having high response time in android app?

I have a java API that is taking around 50 sec to return the response and improvement in API is not possible. 我有一个Java API,大约需要50秒才能返回响应,因此无法改善API。 User can not proceed in next page until the response is complete and it is kind of blocker in the android app which is using the API. 在响应完成之前,用户无法进入下一页,这是使用API​​的android应用中的一种阻止程序。 Please suggest some alternate approach on this. 请为此提出一些替代方法。

For example: we can have two table and API will return the data from table instead waiting for the result of query which is taking more time and we can spawn a thread to run the query in the background and update the table data with the result. 例如:我们可以有两个表,API将从表中返回数据,而不是等待查询结果,这会花费更多时间,我们可以生成一个线程在后台运行查询并使用结果更新表数据。 Based upon time stamp in response data android app can know the data is old or latest and in case of old data they can request it again after some time to get the latest data. 根据响应数据中的时间戳,Android应用程序可以知道数据是旧数据还是最新数据,如果是旧数据,他们可以在一段时间后再次请求获取最新数据。

Please let me know if the question or approach is not clear. 如果问题或方法不清楚,请告诉我。

There is specific way of doing such things. 有做这种事情的特定方法。 There is a thing called Loader in android. android中有一个叫做Loader的东西。 CursorLoader is used for content providers. CursorLoader用于内容提供程序。 and AsyncTaskLoader for api calls AsyncTaskLoader用于api调用

Try this 尝试这个

  if (BuildConfig.DEBUG) {
    HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
    httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    httpClient.addInterceptor(httpLoggingInterceptor);
}

also add this dependencies in gradle app level 还在gradle应用程序级别添加此依赖项

compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'

Smaple response 枫反应

Date: Fri, 12 Aug 2016 07:33:23 GMT
OkHttp-Sent-Millis: 1470987074283
OkHttp-Received-Millis: 1470987074422

You can do it in background Service. 您可以在后台服务中执行此操作。 And notify UI thread when get response through broadcast. 并通过广播获得响应时通知UI线程。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 由于Spring Boot应用程序中存在GC,因此响应时间很高 - High response time because of GC in spring boot app 如何处理API JSON响应,它在JSON名称字段中具有值 - How to deal with API JSON response, which is having value in JSON name field How to get api request and api response time in Android Retrofit api using OkHttp Interceptor for each api? - How to get api request and api response time in Android Retrofit api using OkHttp Interceptor for each api? 如何防止Android应用程序中使用的文件的直接URL访问? - How to prevent direct URL access of a file which is used in an Android app? 如何在Android Game App中保存高分 - How to save high score in Android Game App 打开交易的响应时间长 - High response time for opening an tranasactionn 如何从 OAuth2 客户端应用程序中的授权服务器获取作为访问令牌响应一部分的附加信息 - How to get additional information which is part of access token response from authorization server in OAuth2 client app 如何从android(java)中的json响应中获取内部索引对象,该对象对rest api调用使用改造 - How to get inner indexed object from json response in android (java) which use retrofit for rest api calls 如何更改仅在应用启动时首次启动的 Android 应用活动 - How to change the Android app activity which starts only for first time on app startup 如何优化 REST API 响应时间 - How to Optimize REST API Response time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM