简体   繁体   English

在不锁定手机的情况下下载大量数据并保存的最佳方法是什么(Android Studio)

[英]What is the best way to download large amount of data and save it without locking the phone (Android Studio)

I am working on an Android project (JAVA), but i need to download many line of a database from a server like 3.5K lines , my questions is - what is the best way to download large data without letting the phone become slow , because i used Retrofit and also XmlAsyncTask , but cos of the data to download are much , as I download each time the phone almost crashes,我正在开发一个 Android 项目(JAVA),但我需要从服务器下载多行数据库,比如 3.5K 行,我的问题是 - 下载大数据而不让手机变慢的最佳方法是什么,因为我使用了 Retrofit 和 XmlAsyncTask ,但是要下载的数据的成本很多,因为我每次手机几乎崩溃时都会下载,

despite the fact that i used background threads.尽管我使用了后台线程。 so what is the best way to do to avoid the phone crash with eavy data.那么什么是避免电话崩溃的最佳方法是 eavy 数据。

Thanks.谢谢。

Maybe you are receiving to much data in one request, this data is stored in memory before it can saved in another source and this is the reason that block your phone.也许您在一个请求中收到了大量数据,这些数据先存储在内存中,然后才能保存在另一个来源中,这就是阻止您手机的原因。 The way to use retrofit and background thread is the correct, so you only have to manage the way that you are receiving the data, get it in small amounts recursively and store it in a physical source.使用改造和后台线程的方法是正确的,因此您只需管理接收数据的方式,以少量递归方式获取并将其存储在物理源中。 I suggest RXJava or Kotlin Coroutines for this kind of operations because is easier and works very well together.我建议使用 RXJava 或 Kotlin Coroutines 进行此类操作,因为它们更容易并且可以很好地协同工作。 I hope that it works for you.我希望它对你有用。 Regards.问候。

In any scenario you should contemplate a reconstruction scenario.在任何情况下,您都应该考虑重建方案。 In that case, you maintain the request alive?在那种情况下,你保持请求活着? Maybe you can divide a huge request into a small and successive requests...也许你可以将一个巨大的请求分成一个小的连续的请求......

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM