Memory Issue With Viewpager
Solution 1:
You must attach your views to pager in instantiateItem() (like you do it in regular adapter's getView() method). In this case ViewPager takes care about memory management. Take a look into demo project in CompatibilityPackage. Actually you can have thousands of pages without any lags.
@OverridepublicObjectinstantiateItem(View collection, int position) {
View v = layoutInflater.inflate(...);
...
((ViewPager) collection).addView(v,0);
return tv;
}
@OverridepublicvoiddestroyItem(View collection, int position, Object view) {
((ViewPager) collection).removeView((TextView) view);
}
Solution 2:
hm, my idea is to catch the event "onPageChanged()" in the ViewPager and set the webview after the page has changed - or, to preload as example a page so you have the "scroll effect": you do the following:
as example, you have a count of 10 pages. if your viewpager is at page 0, then you instanciate and load the pages 0,1,2. if your viewpager is at screen 4, then you remove the webviews at positions 0,1 and 7,8,9...
in this way you dont need all instances of webviews (webkit consumes a lot of memory) and have some more memory.
Post a Comment for "Memory Issue With Viewpager"