Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Save images to SQLite or SDCard or memory

Tags:

android

sqlite

I need to fetch images and some other data from server and then display it in the List. But as the number of records can be pretty large so I am not sure if I should save images to SQLite database or save it to SDCard or save those to memory.

Thanks, nil

like image 898
nilMoBile Avatar asked Feb 14 '12 07:02

nilMoBile


People also ask

Can images be stored in SQLite?

Inorder to store images to android SQLite database, you need to convert the image uri to bitmap then to binary characters that is, bytes[] sequence. Then set the table column data type as BLOB data type. After retrieving the images from DB, convert the byte[] data type to bitmap in order to set it to imageview.

Is SQLite good for Android?

Android SQLite is a very lightweight database which comes with Android OS. Android SQLite combines a clean SQL interface with a very small memory footprint and decent speed. For Android, SQLite is “baked into” the Android runtime, so every Android application can create its own SQLite databases.

Why we use SQLite database in Android?

SQLite Database is an open-source database provided in Android which is used to store data inside the user's device in the form of a Text file. We can perform so many operations on this data such as adding new data, updating, reading, and deleting this data.

Can I store image in database?

To insert images into a database, the database must support images. Images are stored in binary in a table cell. The data type for the cell is a binary large object (BLOB), which is a new SQL type in SQL3 for storing binary data.


2 Answers

Always make a habit of saving images path to database. For a list view, be sure just to use those image's thumbnail. This will help you in fast loading of these images in list.

 long selectedImageUri = ContentUris.parseId(Uri.parse(anniEntry.getUri()));
 Bitmap bm = MediaStore.Images.Thumbnails.getThumbnail(
                    mContext.getContentResolver(), selectedImageUri,MediaStore.Images.Thumbnails.MICRO_KIND,
                    null );

Here anniEntry.getUri() is the image uri.Now,put it in second code.U can get micro or mini thumbnail according to requirement

like image 75
Shahzad Imam Avatar answered Sep 19 '22 07:09

Shahzad Imam


It's generally considered bad form to save binary data like an image in a database. In most cases, for some technical reasons, it will actually end up damaging the performance of your database. Instead, save the images you want to cache to the SD card and just store the filepath of those images in the database.

like image 42
Kurtis Nusbaum Avatar answered Sep 18 '22 07:09

Kurtis Nusbaum