0

So i have 6 categories of pictures and each category has like 150-200 pictures. Each picture has a size of 1MB-10MB. Im not sure how to optimise the loading of the pictures. My ViewPager shows 4 pictures at the same time from 1 category which is selected and can swipe trough all pictures of that category. Could someone lead me in the right direction? Im new to android/programming and everything i have found yet is to complicated.

Thanks.

Edit: I also have a 270MB movie that im not sure how to load so it feels "fast".

Daniel Storch
  • 327
  • 1
  • 3
  • 15

2 Answers2

3

I have used this library countless times, it automatically caches the image if the user later returns to the View.

Universial image loader

FuzzyAzu
  • 31
  • 4
  • Same here. I've used this library so many times and its just awesome. Recommended! – Zeeshan Ahmed Oct 01 '14 at 07:51
  • My problem right now is that when the ViewPager gets called the first time, it loads all pictures at the same time. Also the method destroyItem dos not get called. – Daniel Storch Oct 01 '14 at 08:47
  • Have you ever tried to run memory analyzer tool(MAT) with this library. When there are more number of images this library has 3 times more number of HashMap child objects. This can lead to memory leak at some point. – Suhail Mehta Oct 01 '14 at 09:05
  • Found the problem, now im looking into to optimise it with the Universial image loader. Thanks – Daniel Storch Oct 01 '14 at 11:04
0

First of all, use FragmentStatePagerAdapter for your ViewPager. It will prevent OutOfMemory errors due to the large number of images.

http://developer.android.com/reference/android/support/v4/app/FragmentStatePagerAdapter.html

Second, use Picasso for your image loading, and consider resizing your images down, because you probably don't need full resolution for them to look nice.

https://github.com/square/picasso

And third, if you can let user to choose his favourite video player from the list of installed apps, you should do so.

Android intent for playing video?

Community
  • 1
  • 1
Tomislav Novoselec
  • 4,570
  • 2
  • 27
  • 22
  • I have resized my images to the resolution i need thanks. But my problem right now is that all my images get loaded the first time i call the view pager and not only 4-5 which are showing. – Daniel Storch Oct 01 '14 at 09:01
  • How did you implement your ViewPager's adapter? – Tomislav Novoselec Oct 01 '14 at 09:03
  • After you asked i found this: pager.setOffscreenPageLimit(adapter.getCount()); and that the Hardware acceleration was disabled. Solved my problem. Thanks anyway – Daniel Storch Oct 01 '14 at 11:03