Store ArrayList<CustomClass> into database Android - android

I have a Array list of a custom class which contain a bitmap image and a String. I want to store it in database/sharedpreferences when my app will closed and retrieve it when app is created. I already searched on google but it doesn't helped much.
Thank you for your help.

I would not recommend you storing images directly in database (I assume you are using SQLite). The cursor you get from SQLite is limited to 1MB, so if you image is in a reasonable quality, you will not get all the bytes. The best approach, in my opinion, is storing the PATH to the file in the Database, and then, in code, get that path and create a bitmap from file.

Related

Is conversion of image to byte array in android heavy task?

I am converting image as a byte array to store in the database in android. For this, I have to convert image both at the time of storing and reading. I can definitely store all image in variables during runtime at once but it might take a lot of space if there are a lot of images in the database. Does conversion actually take a lot of resources ? in that case I will use other methods to store like in file (I haven't used file before so will have to learn it first, trying to save effort :) ).
I think it depends on how many images are you planning to save in the database. For instance: if it is the user profile image, which is gonna be one image per user, I think it is okay. But, if it is something like images that the user can upload as many images as he likes, I don't really think it is a good idea. There are advantages and disadvantages on both.
There are plenty discussions about those two approaches:
Storing images in a database versus a filesystem
Why is it considered bad to store images in a database?
Storing Images in DB - Yea or Nay?
What is the best place for storing uploaded images, SQL database or disk file system?

Android: uploading user images to server (Volley/Blob)

I want to perform a simple action, to upload user images from the app to online server to store them and to have them available for future uses.
For that purpose, I will use Volley library.
Basically I would convert the image into Base64 format, send it to server, and store it.
My question, however, is that I have read answers to other questions here at stackoverflow about BLOB for storing data into database. Could anyone explain if BLOB is needed in this case or if am I mixing concepts here?.
INFO: My initial idea is to store the images in another folder in the server, and maybe the name and the path to the images in the database...but not the image in the database.
Making your own external Folder for saving images would be better than saving the Images in the database , because when you save the images as BLOB in the database some of the problems you face in database transfer is that, the database becomes to huge to transfer , but when you create a folder aside and you just call the names of the images in the Database , that is much more better. and Volley is also good in this.
If you need like a code sample i can post it
Thanks .

Android: Working with images and SQLite [duplicate]

This question already has answers here:
What is the best way to store the image in the memory of app?
(4 answers)
Closed 6 years ago.
I'd like to be able to programmatically work with Images, ImageViews, Drawables, and SQLite blobs (byte arrays). I inevitably want to be able to have a program that lets me acquire images from the Gallery app or something similar (ie camera), and then place them in a gallery construct within my app and work with them from there. Storing them in SQLite database's as needed.
I haven't come across anything that works. Much of it is deprecated. I have a simple project that is working with text in a SQLite database, and am now trying images.
If you can show or send me someplace that shows how to work with these constructs that would be great. Though to be more specific for this thread I'll state a few things I'd like to do:
Converting Drawables to ImageViews and converting Drawables to SQLite blobs.
Acquiring images from outside the program and placing them in the Drawables section.
Best constructs for working with images.
Thanks,
convert a image to byte[] and easy to store SQlite db
Don't store images in SQLite, instead of saving images save their path into SQLite, and later you can load image from their path.
and if you are loading images from web then you can use Universal Image Loader. It will display and store images in device memory and you can load images offline anytime with same url.
Instead of saving image as blob, save the image url. Or save it in external file in sd card or phone memory.
To save it in a link,
When the user selects an image from gallery. Call the upload image function ( it can be a BoundService ). You can find it by googling it.
When the upload image is successfull, ull get the image url in Json.
Just save that image link in your sqlite database.
Hope it helps.

How should images be manages in Android when not through SQLite

I have some entities which I hold in SQLite DB.
Some of these entities will have image as well, as I read, SQLite DB can return up to 2MB per cursor, so storing the images in the DB isn't an option.
So I guess we are left with internal storage and self managing.
Are there any support libraries for managing these images ?
Is there a recommended design for this ?
I though about saving the images with a filename scheme of entityType_id.png where the id is the entity id in the SQLite DB, but I'm afraid it may change over time (backup / restore and such) so maybe another scheme might be a better solution ?
I used the solution that you mentioned here:
I though about saving the images with a filename scheme of entityType_id.png where the id is the entity id in the SQLite DB, but I'm afraid it may change over time (backup / restore and such) so maybe another scheme might be a better solution ?
I created a folder in my Android project and used ids that will never change. Knowing the folder and the id, which I retrieve from the DB, I am able to get the image. I used the android SQLite asset helper library for the solution.
I used such an approach for this little app: MTBcat. You can find an example here: http://www.6020peaks.com/2015/03/how-to-ship-an-android-app-with-preloaded-data/
You should store all of images on the internal storage. There is a post about that with piece of code, which could be helpful for you:
Capturing and Saving an image in Android with different names and then retrieving it by any of those names?
EDIT:
I mean external storange not internal
Have some sequence to generate unique ids (maybe just store current value as property), and store the id only in the database. Name the image file by id and store the file somewhere in the file system. If you delete the record, remove the file and do not reuse the id.
Generate own ids, independent from what the database is doing. Then they will not be affected by backup/restore or things the like.
I think storing an image which size is more than 2M in sqlite is not good for reading or whiting,maybe you can compress your image before you store it.

Inserting an image into a pre-developed SQLite DB for use with Android

Ive developed a DB for use with my app but I've realised that I actually want extend my db to incorporate images! I will be hosting the db online but for now I am using it locally for development purposes. To create my db I have been using SQLiteBrowser, which I think is a standalone version of the Firefox SQLiteManager plugin, however I cant see a way to insert an image. I recognise that an image will have to be transfered into a byte array and stored as a blob, but rather that developing this element of the db programatically, I was wondering if the was a gui tool to help me skip this developmental element!
Cheers
Sometimes it makes more sense to store the image on disk and only put the file location in your DB. Then you can skip the whole blob <-> byte array conversion and use normal file operations to load the images.
I know that didn't answer your specific question, but if you change your process to the above you might not need the original method, and may save some time and effort as a bonus.

Categories

Resources