我刚刚浏览了Android Developer Site,刷新了Activity Life周期,在每个代码示例中,超类方法旁边都有一条注释,"首先调用超类方法".
虽然这在创建半周期中有意义:onCreate,onStart和onResume,但我对于破坏半周期的正确程序有点困惑:onPause,onStop,onDestroy.
在破坏实例特定资源可能依赖的超类资源之前,首先销毁实例特定资源是有意义的,而不是反过来.但是注释建议不然.我错过了什么?
编辑:由于人们似乎对问题的意图感到困惑,我想知道的是以下哪一项是正确的?为什么?
1.Google建议
@Override
protected void onStop() {
super.onStop(); // Always call the superclass method first
//my implementation here
}
Run Code Online (Sandbox Code Playgroud)
另一种方式
@Override
protected void onStop() {
//my implementation here
super.onStop();
}
Run Code Online (Sandbox Code Playgroud) 可以将View Pager设置为自动滑动或自动播放.我将我的viewpager设置为使用如下所示的适配器,它工作正常: -
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gridslide);
ImagePagerAdapter mAdapter = new ImagePagerAdapter(
getSupportFragmentManager(),4);
ViewPager mPager = (ViewPager) findViewById(R.id.pager);
mPager.setAdapter(mAdapter);
}
Run Code Online (Sandbox Code Playgroud)
适配器如下: -
public static class ImagePagerAdapter extends FragmentStatePagerAdapter {
private final int mSize;
public ImagePagerAdapter(FragmentManager fm, int size) {
super(fm);
mSize = size;
}
@Override
public int getCount() {
return mSize;
}
@Override
public Fragment getItem(int position) {
Log.v(TAG,"position="+position);
return TheFragment.newInstance(position);
}}
Run Code Online (Sandbox Code Playgroud)
但是,我想知道如何在viewpager中使这些片段自动滑动.