简体   繁体   中英

What is the Best practice to store the image in Room database in android?

i got image content uri from activity result like this

val imagePickerLauncher = rememberLauncherForActivityResult(contract = ActivityResultContracts.GetContent(), onResult = { uri->
    it?.let {
        profilePhoto = uri.toString()
    }
})
  1. should i convert it to byte array and store it as blob?
  2. should i copy the file to app specific folder and store that path to room?

bast solution to do this

Option 1 May or may not be feasible/practical due to how the Android API retrieves data via a Cursor.

Option 1 would, again depending upon the size, possibly (probably) make poor use of the buffering and be inefficient and thus resource intensive.

As such Option 2 is considered the recommended approach even though in some circumstances SQLite can be more efficient/faster for storing data as per SQLite 35% faster than the Filesystem

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM