Reputation: 1
I have the following case:
Activity1
public class Activity1 extends Activity{
ImageUtils.setArt(bitmap);
}
Activity2
public class Activity2 extends Activity{
Bitmap b= ImageUtils.getArt();
}
ImageUtils
public class ImageUtils{
private static Bitmap mArtWork;
public static Bitmap getArt(){
return mArtWork;
}
public static void setArt(Bitmap art){
this.mArtWokr=art;
}
Now, I need a good approach, to share Bitmap
s among different Activity
s.
Since static
variables will not be Garbage Collected during my application execution, I need a good way to share the images amongst my scenarios.
I am considering using a singleton "ImageUtils" to hold my images, and then access then.
I have considered and disregarded passing pareaceable bitmaps, and even sharing URI through intents, but those have had bad results.
Are there better approaches?
Upvotes: 0
Views: 66
Reputation: 121
Try to use Memory Cache (LRU cache for example) or Disk cache (File I/O for example). This is the suggested way by Google about how to caching bitmaps. The google documents is here.
Set size of yur LRU cache. If the whole images size exceed the maiximun of the LRU cache you set, the least recently used images will be deleted.That's how LRU cache works. While if you save the images on the disk, don't forget to delete the images when you finish using them.
Upvotes: 1
Reputation: 3190
It's not a good idea to pass a bitmap through memory, because bitmap isn't been compress in memory. Maybe try to save it into a temp file, and load in another activity...
Upvotes: 0