Does resource id changes everytime an application starts

前端 未结 3 975
后悔当初
后悔当初 2020-12-17 23:06

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

3条回答
  •  青春惊慌失措
    2020-12-18 00:05

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

     
        @drawable/ic_image_name
        @drawable/ic_image_name
        @drawable/ic_image_name
        @drawable/ic_image_name
        @drawable/ic_image_name
        @drawable/ic_image_name
        @drawable/ic_image_name
    
    

    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

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

     locationFlags.recycle();
    

提交回复
热议问题