android – "Can not perform this action after onSaveInstanceState" exception after rotate device-ThrowExceptions

Exception or error:

I have a ViewHolder and in bindView() method set a OnLongClickListener.

When I rotate device and long click on list item java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState exception occurs.

I’ve already override show() method and tested commitAllowingStateLoss but still get exception.

Anyone can help me?

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;
        });
    }
}
How to solve:

I solved the problem by a delegation…

  1. Add checkFingerprintAuthentication() method in Caller Class:

    void checkFingerprintAuthentication() {
        FingerprintDialogFragment fingerprintDialogFragment = FingerprintDialogFragment.getInstance(this);
        fingerprintDialogFragment.show(getActivity().getSupportFragmentManager(), FINGERPRINT_DIALOG_TAG);
    }
    
  2. Send Caller Class as a parameter to View Holder and call checkFingerprintAuthentication():

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

problem solved! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *