Paul Ledger
Paul Ledger

Reputation: 1135

Pre loading images into a variable

I am trying to change an image in my app depending on the position of the phone using the accelerometer. This isn't where I'm stuck, its not to hard to do. I have an array of images from my drawable folders that change depending on the angle of the device. This works fine (switching the image of the imageview), with low res images but what would like to know is, is there a way or preloading images in java like I can in JavaScript when creating rollover images. So the hi res images would change seamlessly like the low res images.

Upvotes: 0

Views: 118

Answers (2)

luckybilly
luckybilly

Reputation: 231

https://github.com/luckybilly/PreLoader can resolve your problem.

you can pre-load almost everything you need with PreLoader. And you don`t need to worry about it not completed when you should get it: DataListener.onDataArrived(data) will be called after pre-load is completed

Upvotes: 0

Peri Hartman
Peri Hartman

Reputation: 19474

Yes. Create a subclass MyApp of Application.

In MApp.onCreate() you can preload your images; e.g.

image1 = getResources().getDrawable (R.drawable.image1);

And in your app, you simply do something like

image1 = ((MyApp)getApplication()).getImage1();

where getImage1 is a getter you provide in MyApp.

Hope this works for you!

Upvotes: 1

Related Questions