这是我的代码:
public class CustomSwipeAdaptor extends PagerAdapter {
private int[] image_resources={R.drawable.aa,R.drawable.bb,R.drawable.cc};
private Context ctx;
private LayoutInflater layoutInflater;
public CustomSwipeAdaptor(Context ctx)
{
this.ctx=ctx;
}
@Override
public int getCount() {
return image_resources.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return (view==(LinearLayout)object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater=(LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE );
View item_view=layoutInflater.inflate(R.layout.swipe_layout,container,false);
ImageView imageView=(ImageView)item_view.findViewById(R.id.image_view);
imageView.setImageResource(image_resources[position]);
container.addView(item_view);
return item_view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((LinearLayout)object);
}
}
public class Chapter1 extends AppCompatActivity{
ViewPager viewPager;
CustomSwipeAdaptor adaptor;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chapter1);
viewPager=(ViewPager)findViewById(R.id.view_pager);
adaptor=new CustomSwipeAdaptor(this);
viewPager.setAdapter(adaptor);
}
}
这是我的logcat:
06-12 18:45:05.631 341-349/com.example.kips.itapps W/art: Suspending all threads took: 7.170ms
06-12 18:45:27.677 341-349/com.example.kips.itapps W/art: Suspending all threads took: 6.168ms
06-12 18:47:31.577 341-349/com.example.kips.itapps W/art: Suspending all threads took: 7.052ms
06-12 18:48:36.275 341-349/com.example.kips.itapps W/art: Suspending all threads took: 5.650ms
06-12 18:56:21.208 341-349/com.example.kips.itapps W/art: Suspending all threads took: 8.523ms
答案 0 :(得分:0)
这在很大程度上是无害的。来自here
Java代码堆是一个共享资源。对于ART中的GC暂停, 必须暂停线程,以便它们不会更改堆和 打破GC不变量。暂停线程局部变量的线程 由GC修改,然后线程观察到这种变化和 放弃变异锁定,然后GC将保持锁定 独家经营。当线程被挂起而其他线程被挂起 放弃他们对变种锁的份额,这对于jank来说很重要 线程及时响应。 5ms几乎是16ms的1/3 当线程悬挂缓慢时,ART会发出警告。作为+ Aladin Q说这可能会带来很多负担。如果它发生了 经常,或没有负载,它可能是可能的错误的证据 因为jank。
除非您遇到严重问题阻止您的应用实现其目标,否则它是良性的,以及several other similar log outputs。