In my application I use ViewPager
for show some data and I want set auto scroll between of pages in every 5sec.
I use below code for auto scroll between of pages in every 5sec.
private int page = 0;
private Handler handler;
private int delay = 5000;
private Runnable runnable = new Runnable() {
public void run() {
if (homeRecentPostAdapter.getCount() == page) {
page = 0;
} else {
page++;
}
homePage_recentViewPager.setCurrentItem(page, true);
handler.postDelayed(this, delay);
}
};
homePage_recentViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
page = position;
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
Without use this Thread
and Handle
memory usage (into profiler tab) has 80mb, but after use above codes for set auto scroll memory usage upper to 120mb and every 5 set upper this usage, then after 2min receive to 250mb !
How can I fix it? how can use auto scroll without increase memory ?
check your
ViewPager
, maybe it is creating new instance on each page turn. If your provide the code I might be able to point it out.