How can ленивую content be loaded into the application?

In some games, additional content is loaded by agreement with the user, after the application is launched. How to implement a similar mechanism?

Closed due to the fact that the issue is too general for Kromster , Denis Bubnov , Monk , αλεχολυτ , Streletz Mar 31 '17 at 19:29 .

Please correct the question so that it describes the specific problem with sufficient detail to determine the appropriate answer. Do not ask a few questions at once. See “How to ask a good question?” For clarification. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Too general question. Apparently you need to download image files from the server, and then load them into textures. - Unick
  • @Unick, I’m interested in the principle itself, I’ll find the implementation for a specific engine. So far, all I've seen is the loading of local textures. - ravend
  • Those. Your question can be reduced to how after launching the application to load files from the server? In your situation, the image. - Unick
  • @Unick, I wanted to load the image (on demand) on the device and continue to use it as a local resource - ravend

1 answer 1

This is done something like this.

Suppose there is an ImageView , in which you need to download a large file from an external source. In principle, texture loading is not much different from loading an image, so this can be omitted.

1) We must take care to stub / stub'om pictures. It can either be generated in advance and put into resources or it can be generated programmatically in the form of a Thumbnail, for example:

  Bitmap ThumbImage = ThumbnailUtils.extractThumbnail( BitmapFactory.decodeFile(imagePath), THUMBSIZE, THUMBSIZE); 

2) At the time of the layout sweep, we will load a stub instead of our ImageView / thumbnail

3) Next, run AsyncTask in which we AsyncTask image from an external source in the doInBackground() method. When AsyncTask completes in the onPostExecute() method, onPostExecute() already replace the stub with the downloaded picture.

Lieb do many jobs like this, for example universalImageloader or newfangled Picasso