Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
503 views
in Technique[技术] by (71.8m points)

android - Does resource id changes everytime an application starts

I am storing my images in drawable and their resource id in SQLite database.My database is created when the application starts for the first time.

Is it good to save the image ids in database or does the id's change every time an application start?

if id's change then while fetching back image id's I may receive an error.So,is storing image ID in database a good idea?

i need the images path to be stored in database with other relative data that's why i am storing the image id's in data base.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

One approach would be storing the drawables in strings.xml as a string array something like this:

 <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>

Then reading this array in your activity code :

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

Then applying the for loop you can get the Drawable something like this:

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

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

Be sure to recycle the TypedArray after using it, since its a shared resource :

 locationFlags.recycle();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...