旋转设备后出现“ onSaveInstanceState之后无法执行此操作”异常

时间:2018-07-12 15:33:30

标签: android dialogfragment onsaveinstancestate

我有一个ViewHolder,并在bindView()方法中设置了一个 OnLongClickListener

当我旋转设备并长按列表项 java.lang.IllegalStateException:在发生onSaveInstanceState 异常后无法执行此操作。

我已经重写了show()方法并测试了 commitAllowingStateLoss ,但仍然出现异常。

有人可以帮助我吗?

public void bindView(final FragmentActivity activity) {

    ...

    itemView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            FingerprintDialogFragment fingerprintDialogFragment = FingerprintDialogFragment.getInstance(DecreeItemViewHolder.this);
            fingerprintDialogFragment.show(activity.getSupportFragmentManager(), FINGERPRINT_DIALOG_TAG);

            return true;
        });
    }
}

1 个答案:

答案 0 :(得分:0)

我通过委派解决了问题...

  1. 呼叫者类中添加 checkFingerprintAuthentication()方法:

    void checkFingerprintAuthentication() {
        FingerprintDialogFragment fingerprintDialogFragment = FingerprintDialogFragment.getInstance(this);
        fingerprintDialogFragment.show(getActivity().getSupportFragmentManager(), FINGERPRINT_DIALOG_TAG);
    }
    
  2. 将呼叫者类作为参数发送给查看持有者,并调用 checkFingerprintAuthentication()

    public void bindView(final DecreeCartableController cartableController) {
        ...
    
        itemView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
                cartableController.checkFingerprintAuthentication();
                return true;
           }
       });
    }
    

问题解决了! :)