问题
In some phones (especially Samsungs), the application gives an error of OutOfMemory.
I use a ViewFlipper with 4 ImageViews which they are shown in a tutorial.
I have found no way to remedy the error or recycle imageviews.
This is the method that manages the ViewFlipper:
private void changeBackground(int position) {
switch (position) {
case 1:
mViewFlipper.setDisplayedChild(1);
mViewFlipper.setInAnimation(getActivity(), R.anim.anim_clockwise_onboarding);
mViewFlipper.setOutAnimation(getActivity(), R.anim.anim_clockwise_inverse_onboarding);
break;
case 2:
mViewFlipper.setDisplayedChild(2);
mViewFlipper.setInAnimation(getActivity(), R.anim.anim_clockwise_onboarding);
mViewFlipper.setOutAnimation(getActivity(), R.anim.anim_clockwise_inverse_onboarding);
break;
case 3:
mViewFlipper.setDisplayedChild(3);
mViewFlipper.setInAnimation(getActivity(), R.anim.anim_clockwise_onboarding);
mViewFlipper.setOutAnimation(getActivity(), R.anim.anim_clockwise_inverse_onboarding);
break;
default:
mViewFlipper.setDisplayedChild(0);
mViewFlipper.setInAnimation(getActivity(), R.anim.anim_clockwise_onboarding);
mViewFlipper.setOutAnimation(getActivity(), R.anim.anim_clockwise_inverse_onboarding);
break;
}
}
The method is called each time you change pages in a ViewPager.
@Override
public void onPageSelected(int position) {
changeBackground(mViewPager.getCurrentItem());
}
If any have idea please help me, Thanks in advance.
回答1:
For that you need to use Image loader library for loading images. You can use :
- Universal Image loader
- Picasso
- Glide
This library uses for bitmap memory management and after using this library you didn't face OutOfMemoryError exeption.
来源:https://stackoverflow.com/questions/36354229/recycle-imageviews-to-avoid-outofmemoryerror