Source:
<code>void moreSettings() { popup.setOnMenuItemClickListener(item -> { switch (item.getItemId()) { case R.id.toggleBeep: editor = sp.edit(); if (mRing) { mRing = false; item.setChecked(false); editor.putBoolean("ring", false); } else { mRing = true; item.setChecked(true); editor.putBoolean("ring", true); } editor.apply(); break; case R.id.toggleAutofocus: if (barcodeView.getBarcodeView().isPreviewActive()) { barcodeView.pause(); } editor = sp.edit(); CameraSettings settings = barcodeView.getBarcodeView().getCameraSettings(); if (mAutofocus) { mAutofocus = false; settings.setAutoFocusEnabled(false); item.setChecked(false); editor.putBoolean("focus", false); } else { mAutofocus = true; settings.setAutoFocusEnabled(true); item.setChecked(true); editor.putBoolean("focus", true); } barcodeView.getBarcodeView().setCameraSettings(settings); barcodeView.resume(); editor.apply(); break; case R.id.troubleScanning: hideAllViews(); handler.removeCallbacks(runnable); quickView.setOnClickListener(null); searchByBarcode.setText(null); searchByBarcode.setVisibility(View.VISIBLE); quickView.setVisibility(View.INVISIBLE); bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); new Handler().postDelayed(new Runnable() { @Override public void run() { <START> runOnUiThread(new Runnable() { <END> @Override public void run() { quickView.setVisibility(View.VISIBLE); } }); } }, 500); searchByBarcode.requestFocus(); break; case R.id.toggleCamera: toggleCamera(); break; } return true; }); popup.show(); }</code><technical_language>runOnUiThread is necessary code is executing UI thread (the handler is instantiated button_more click executes UI thread. please change it). instantiated class member **handler** instead of instantiating new handler time click? please change</technical_language>

Target:
void moreSettings() { popup.setOnMenuItemClickListener(item -> { switch (item.getItemId()) { case R.id.toggleBeep: editor = sp.edit(); if (mRing) { mRing = false; item.setChecked(false); editor.putBoolean("ring", false); } else { mRing = true; item.setChecked(true); editor.putBoolean("ring", true); } editor.apply(); break; case R.id.toggleAutofocus: if (barcodeView.getBarcodeView().isPreviewActive()) { barcodeView.pause(); } editor = sp.edit(); CameraSettings settings = barcodeView.getBarcodeView().getCameraSettings(); if (mAutofocus) { mAutofocus = false; settings.setAutoFocusEnabled(false); item.setChecked(false); editor.putBoolean("focus", false); } else { mAutofocus = true; settings.setAutoFocusEnabled(true); item.setChecked(true); editor.putBoolean("focus", true); } barcodeView.getBarcodeView().setCameraSettings(settings); barcodeView.resume(); editor.apply(); break; case R.id.troubleScanning: hideAllViews(); handler.removeCallbacks(runnable); quickView.setOnClickListener(null); searchByBarcode.setText(null); searchByBarcode.setVisibility(View.VISIBLE); quickView.setVisibility(View.INVISIBLE); bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED); new Handler().postDelayed(new Runnable() { @Override public void run() { quickView.setVisibility(View.VISIBLE); } }, 500); searchByBarcode.requestFocus(); break; case R.id.toggleCamera: toggleCamera(); break; } return true; }); popup.show(); }