Crash when rotating Activity using ViewFlipper

限于喜欢 提交于 2019-12-04 21:10:44

Indeed this is a bug in the bowels of Android. You can work around it by using a "SafeViewFlipper" instead:

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ViewFlipper;

public class SafeViewFlipper extends ViewFlipper {


    public SafeViewFlipper(Context context) {
        super(context);
    }

    public SafeViewFlipper(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void onDetachedFromWindow() {
        try {
            super.onDetachedFromWindow();
        }
        catch (IllegalArgumentException e) {
            // This happens when you're rotating and opening the keyboard that the same time
            // Possibly other rotation related scenarios as well
            stopFlipping();
        }
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!