-3

I want to get an image and store it in sqlite what should I do?

For example user clicks on button and picks an image from gallery now I want to store it in sqlite and show that image on another one activity.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Mmd
  • 23
  • 1
  • 5
  • 1
    Storing an actual image in a db is usually not a good idea, you should be putting the path to the image in the database – tyczj Oct 10 '17 at 18:10
  • So, what should I do? – Mmd Oct 10 '17 at 18:12
  • you should store the url in your database like I said then get the image when you need it from the url – tyczj Oct 10 '17 at 18:14
  • Here's an example [How to retrieve a large BLOB from database in android?](https://stackoverflow.com/questions/46518604/how-to-retrieve-a-large-blob-from-database-in-android/46519680#46519680). – MikeT Oct 10 '17 at 19:10

1 Answers1

0

In android Phones due to their nature its not a good idea to store images in the Database since it is not thread safe storing byte to byte of the Images. Also its complicated to pass a Bitmap to another Activity and it can lead to Memory Errors.

It may make your app slow an even get ANR (Application Not Responding) errors, So if you want to store Images just store their File path to the folder they are found or Uri to their location. You need some training to ways to get Uri when guiding user to pick the Image which is not under the scope of this question. So consider visiting this question. Also also this external link.

Xenolion
  • 12,035
  • 7
  • 33
  • 48