Explain how to store many images in a local database in an Android application and then display them in an ImageView . I know how to work with ImageView , but here's a problem with the database. Help me please.
Can you drop the code and explain?
- You would indicate more detailed information, but it is not clear that you have a predefined set of images or are downloaded from the Internet, and can be varied. Just with different hands, you can offer different options.) - Vitalii Obideiko
2 answers
You can store images in the database, but there will be a serious performance problem that can be avoided when working with files.
To get the image from the database, you need to read the byte array from the blob into memory, moreover, all at once, which will then be collected by the garbage collector and the application will brake. If there are several such downloads, the application will stutter noticeably, especially if at this moment there are some animations. Immediately, the speed of processing images from a file and from a database differs by 1.5-2 times in favor of the database (Genymotion test).
Therefore, you need to store pictures in files, paths to pictures - in the database. Better yet, save the pictures to disk under the generated names. And it is absolutely correct to use Picasso or UIL for loading, storing, displaying pictures.
Images should be stored in the form of lines-paths to files. The images themselves should not be stored in the database.
Place your images in the project in the assets folder and write the path to them / their names in the database. After get them to these addresses.
- You just don’t have to do this :) - andreich
- @andreich, can you tell us more exactly what and why not to do? =) - YuriySPb ♦
- @YuriySPb, If you use the digital ID from the R file, then adding some resource will regenerate the file, and the values in the database will remain the same.)) - Vitalii Obideiko
- @ VitaliyObideyko, oh, yes, for sure) put it away ) - Yuriyyyy ♦