Does the resource identifier change every time the application starts

I save my images in drawable and their resource identifier in a SQLite database. My database is created when the application is launched for the first time.

Is it good to save image identifiers in the database or is the identifier changed every time the application starts?

if the identifier changes, and when retrieving the reverse image, I can get an error message. So, is the image id well stored in the database?

I need a path to images that will be stored in the database with other relative data, so I save the image identifier in the database.

+4
source share
3

,

int resID = this.getResources().getIdentifier("your photo name fetched from database","drawable","package name");

image.setResourceID(resID);
+2

, strings.xml :

 <string-array name="location_flags">
    <item>@drawable/ic_image_name</item>
    <item>@drawable/ic_image_name</item>
    <item>@drawable/ic_image_name</item>
    <item>@drawable/ic_image_name</item>
    <item>@drawable/ic_image_name</item>
    <item>@drawable/ic_image_name</item>
    <item>@drawable/ic_image_name</item>
</string-array>

, :

TypedArray locationFlags=getResources().obtainTypedArray(R.array.location_flags);

, for, Drawable :

for(int i=0i<locationFlags.length();i++)
 {

   Drawable drawable = locationFlags.getResourceId(i, -1);
 }

TypedArray , :

 locationFlags.recycle();
+2

, ? - , .

  • final int thumbnailSize = 128;//

    ThumbImage = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(imagePath),               THUMBSIZE, THUMBSIZE);

  • = BitmapFactory.decodeResource(getResources(), R.drawable.thumbnail); ByteArrayOutputStream out = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.PNG, 100, out); byte [] buffer = out.toByteArray();

  • Blob

    ContentValues ​​cv = new ContentValues ​​(); cv.put (CHUNK, buffer); // CHUNK BLOB field type of your table long rawId = database.insert (TABLE, null, cv); // Table name TABLE

    I used havnt but this may help you

0
source

All Articles