admin管理员组

文章数量:1316020

I am currently developing an Android app and facing a challenge with fetching data from an API (whose data will likely not be updated in the upcoming years). The data is successfully retrieved and displayed, but the process sometimes takes several seconds, leading to a poor user experience.

I’ve been researching potential solutions and came across two approaches that seem promising, but I’m unsure which would be better for my use case:

  1. Implementing a cache: It would prevent fetching the same data multiple times in a short period. However, data never accessed or not for a while would still require fetching, which might not fully solve the delay issue.

  2. Bundling the data with the app: All the necessary API data would be included as a local, read-only resource (e.g., in a JSON, CSV or TXT file). However, the dataset I need being approximately 15,000 rows with 13 fields each, I’m concerned this approach might impact the app’s performance or efficiency.

Given my scenario, which solution would be more appropriate? Are there any other alternatives I should consider to optimize data loading and improve the user experience?

I am currently developing an Android app and facing a challenge with fetching data from an API (whose data will likely not be updated in the upcoming years). The data is successfully retrieved and displayed, but the process sometimes takes several seconds, leading to a poor user experience.

I’ve been researching potential solutions and came across two approaches that seem promising, but I’m unsure which would be better for my use case:

  1. Implementing a cache: It would prevent fetching the same data multiple times in a short period. However, data never accessed or not for a while would still require fetching, which might not fully solve the delay issue.

  2. Bundling the data with the app: All the necessary API data would be included as a local, read-only resource (e.g., in a JSON, CSV or TXT file). However, the dataset I need being approximately 15,000 rows with 13 fields each, I’m concerned this approach might impact the app’s performance or efficiency.

Given my scenario, which solution would be more appropriate? Are there any other alternatives I should consider to optimize data loading and improve the user experience?

Share Improve this question edited Jan 30 at 18:19 Balizok asked Jan 30 at 12:34 BalizokBalizok 1,0952 gold badges9 silver badges27 bronze badges 10
  • So you load 15 thousand lines with 13 parameters every time you open the application? And how many requests do you send to the server? I tried to estimate the size of the downloaded file 15 000 lines * 13 parameters * 10 characters * 2 bytes = 3.6 Mb, it seems that such a file can be downloaded for several seconds. You say that the 2nd option is possible - to add all data to the application, but in the 1st option you say that data needs to be updated periodically and that leaves only the 1st option. – dmortal Commented Jan 30 at 17:50
  • Maybe before downloading the data, the client will send a request and check the version on the server and in the application and if the data is outdated, it will download new data and save them in the database, but until they are downloaded the user will see the old data. – dmortal Commented Jan 30 at 17:50
  • I'm not downloading everything everytime I open the app, data is only accessed one item at a time. And the data is probably never going to change, thus the option 2 being conceivable imo. I edited my question to clear potential misunderstandings. – Balizok Commented Jan 30 at 18:17
  • But why does it take a few seconds to get a response to a request? Normally requests are executed within 300ms. – dmortal Commented Jan 31 at 6:55
  • That's the thing I don't know, it usually takes a few ms but sometimes there's a huge waiting time, and I don't know if the problem is on my side or the api's. – Balizok Commented Jan 31 at 9:44
 |  Show 5 more comments

1 Answer 1

Reset to default 0

Using the cache and provide feedback to the user on the UI as the data is fetched

本文标签: databaseBest approach to optimize API data fetching in an Android appStack Overflow