volley内存溢出的问题所在
volley内存溢出的问题所在
在网络请求中有网络溢出现象,可能大家很少见到过这种情况,可为了解决这问题。为此学习啦小编为大家整理推荐了,希望大家喜欢。
volley内存溢出
官网上有写,然后创建RequestQueue 的时候用Application的context。If your application makes constant use of the network, it's probably most efficient to set up a single instance of RequestQueue that will last the lifetime of your app. You can achieve this in various ways. The recommended approach is to implement a singleton class that encapsulates RequestQueue and other Volley functionality. Another approach is to subclass Application and set up the RequestQueue in Application.onCreate(). But this approach is discouraged; a static singleton can provide the same functionality in a more modular way.
A key concept is that the RequestQueue must be instantiated with the Application context, not an Activity context. This ensures that the RequestQueue will last for the lifetime of your app, instead of being recreated every time the activity is recreated (for example, when the user rotates the device).
图一:
图二: