我的应用程序在以下情况下崩溃:
然而,如果我在最小化之前等待它完成渲染,或者在最小化之后不旋转设备,它可以正常工作。
我试图找出系统在最小化之后旋转应用程序时所执行的操作。没有日志输出。
我在活动中也有一个ViewPager
。我不确定ViewPager
是否在崩溃中起作用。
崩溃报告如下:
Caused by: java.lang.ArrayIndexOutOfBoundsException: length=2; index=4
at android.app.FragmentManagerImpl.restoreAllState(FragmentManager.java:1750)
at android.app.Activity.onCreate(Activity.java:943)
at android.support.v4.app.FragmentActivity.onCreate(FragmentActivity.java:257)
at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:58)
at com.blackberry.emailviews.activity.SwipeableEmailActivity.onCreate(MyActivity.java:124)
at android.app.Activity.performCreate(Activity.java:6034)
答案 0 :(得分:0)
您是否已将活动android:configChanges="orientation|screenSize"
放入AndroidMAnifext.xml文件中。
使用PagerAdapter示例:
公共类CustomPagerAdapter扩展了PagerAdapter {
public static final String TAG = CustomPagerAdapter.class.getSimpleName();
private Context context;
private ArrayList<Object> data;
private LayoutInflater inflater;
public CustomPagerAdapter(Context context, ArrayList<Object> data)
{
this.data = data;
this.context = context;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public Object instantiateItem(ViewGroup pager, final int curentItem)
{
Log.d(TAG, "instantiateItem called for position " + curentItem);
//Inflate
final View localView = inflater.inflate(R.layout.home_news_slide, null);
if(null!=localView){
final Data currentData= (Data) this.data.get(curentItem);
TextView title = (TextView)localView.findViewById(R.id.title_textview);
TextView date = (TextView)localView.findViewById(R.id.date_textview);
final ImageView imageView = (ImageView) localView.findViewById(R.id.home_slide_image);
//Set
title.setText(currentData.getTitle());
date.setText(Util.dateParse((currentData.getDate())));
imageView.setImageUrl(currentData.getArticleImage(), VolleyService.getInstance(context).getImageLoader());
imageView.setDefaultImageResId(R.drawable.default_img);
imageView.setErrorImageResId(R.drawable.default_img);
//Event listener for Fragment switch
localView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Open some activity
}
});
pager.addView(localView,curentItem);
}
return localView;
}
@Override
public int getCount() {
return data.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object)
{
container.removeView((View) object);
}
}