ahaisting
ahaisting

Reputation: 523

Storing Bitmap for multiple Activities?

I'm looking for a way to store some Bitmaps that can be accessed by multiple activities, without having to be reloaded from the web.

I do NOT want to simply pass them from Activity to Activity by putting them into an Intent, but rather have one place where I can access them without having to pass them.

I looked into caching to help solve this problem, but if this is the solution I'm a little unclear as to how to make the cache accesible in multiple activities.

Any suggestions or alternative solutions would be greatly appreciated.

Upvotes: 4

Views: 808

Answers (3)

Tobias Ritzau
Tobias Ritzau

Reputation: 3327

You can either use LruCache, a library such as Volley, or implement the same functionality yourself. I think that the volley library would be perfect for you.

To access it from anywhere in your application you should either store it in a special application object or in a static variable. Note that only a reference to the cache will be stored there. The size of the cache is in both cases listed above configurable.

Upvotes: 2

Kamen Stoykov
Kamen Stoykov

Reputation: 1881

You can make static array or map of bitmaps and access it from where u want. If there are a lot of images you can also make queue and store only most recent used there.

Upvotes: -1

Yakiv Mospan
Yakiv Mospan

Reputation: 8224

What does the cache accesible in multiple activities means ? Just dowload it from web, save to SD card (chache it) and then load it from SD card from as many Activities as you want.

Here are some example of how you can store data in Android.

You can use Picasso loader for this task.

Upvotes: 0

Related Questions