After Saving the Bitmap resource in a static variable , it seems that storing a static link to android.graphics.Bitmapin Viewmay leak the link to this first Viewone that created it. What is the idiomatic way to solve this problem in Android? I do not want to name BitmapFactory.decodeResource(resource, id)every time an instance of this view is created, because it will be done (many times) in each individual Activity. I want this little one to Bitmapalways be remembered. So what is the correct way to do the following:
android.graphics.Bitmap
View
BitmapFactory.decodeResource(resource, id)
Bitmap
public class MyView extends View { private static Bitmap star; public MyView(Context context) { synchronized(this) { if (star == null) { star = BitmapFactory.decodeResource(getResources(), R.drawable.star); } } } // ... }
, onPause(). recycle() . , , , onResume().
onPause
recycle()
onResume()
, , , , , 0. , onCreate()/onDestroy().
onCreate()
onDestroy()
null .
, . , . , .
.
, null. ( final)
final
why not just load the image into the action in which the views will be displayed, and transfer the bitmap to the views
or if you do this throughout the application, use the application context to download the image.