我试图每隔5秒使用一个计时器更改viewpager页面,一切正常,但每次viewpager页面更改时我都会注意到GC暂停。
我做错了吗?提前谢谢。
后台部分并发标记扫描GC释放143(8KB)AllocSpace 对象,4(41MB)LOS对象,19%免费,65MB / 81MB,暂停1.386ms 总计117.193ms
//Calling every 5 seconds
viewPager.setCurrentItem(nextPage, true)
ViewPagerAdapter.java
public class ViewPagerAdapter extends PagerAdapter {
private final LayoutInflater mLayoutInflater;
private final TypedArray mResources;
public ViewPagerAdapter(Context context, TypedArray resids) {
this.mResources = resids;
mLayoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return mResources.length();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public Object instantiateItem(ViewGroup container, final int position) {
View itemView = mLayoutInflater.inflate(R.layout.viewpager_item, container, false);
ImageView imageView = (ImageView) itemView.findViewById(R.id.imageView);
Context context = imageView.getContext();
//360x540
int currentapiVersion = Build.VERSION.SDK_INT;
if (context != null && currentapiVersion > Build.VERSION_CODES.KITKAT) {
Picasso.with(context)
.load(mResources.getResourceId(position, 0))
.fit()
.into(imageView);
} else if (context != null) {
Picasso.with(context)
.load(mResources.getResourceId(position, 0))
.resize(360, 540)
.into(imageView);
}
imageView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
setas_wall_dialog(v.getContext(), mResources.getResourceId(position, 0));
return false;
}
});
container.addView(itemView);
return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((ImageView) object);
}
}
我尝试删除.fit()
,但问题仍然存在。