简体   繁体   中英

Best way to load assets in android java

I have one android activity with a lot of calculations and everything is ok, but in the final version of my project I need to load a lot of bitmaps and sounds in the same activity and it gets a lot slower than it should be.. Sometimes the activity chrashes itself.

So, is there any advice how should I load all the assets? Should I declare them in separate class, or what?

Basically you only load those assets when you need them and unload them if you do not need them. (Lazy Loading)

Because mobile has limited memory and I am imagining your files are really big you must be careful on how you will manage those files.

For image I recommend this link and try to optimize your image as good as possible

For sounds kindly look at this class and this discussion about loading sound files

OutOfMemoryError when loading large amount of data in Android

Android SoundPool – How to check if sound file is loaded?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM