0

I am working on an application that is being distributed publicly. We have had some issues with soft keyboards showing up when edit text boxes are clicked (this is through an XML popup dialog), and found a solution, by toggling the soft keyboard into a forced state, through an onClickListener. (So it happens on the second click) This is not the issue anymore. The issue is that on our device, the forced keyboard stays open even when the user clicks the home button on their device. I will attach the code I used to get the keyboard to open.

  InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    if(imm.isAcceptingText()){
                        //Toast.makeText(getApplicationContext(),""+imm.isAcceptingText(),Toast.LENGTH_LONG).show();
                    } else{

                        final AlertDialog.Builder dialog = new AlertDialog.Builder(ListResults.this).setTitle("").setMessage("If you are seeing this, please reboot your device.");
                        final AlertDialog alert = dialog.create();
                        alert.show();
                        final Handler handler  = new Handler();
                        final Runnable runnable = new Runnable() {
                            @Override
                            public void run() {
                                if (alert.isShowing()) {
                                    alert.dismiss();
                                }
                            }
                        };
                        alert.setOnDismissListener(new DialogInterface.OnDismissListener() {
                            @Override
                            public void onDismiss(DialogInterface dialog) {
                                handler.removeCallbacks(runnable);
                            }
                        });
                        handler.postDelayed(runnable, 20);
                        }
                      //Toast.makeText(getApplicationContext(),""+imm.isAcceptingText(),Toast.LENGTH_LONG).show();
                editGroup.requestFocus();
                imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);

This is designed to open the keyboard. The AlertDialog is a trick we found to get it to reset the imm.isAcceptingText and allow it to open the keyboard when it is forced. Before this, the keyboard did not open for us.

Now though, when anyone hits the home button on our android devices, the keyboard stays in the home screen until we click the back button, as I stated above. Is there a way to fix this, or some sort of work around to resolve this issue? I want the keyboard to close when the app is put into the background.

RadioSam
  • 1
  • 3
  • Try using InputMethodManager to explicitly hide the keyboard in onPause. That may work. I'm not sure why you're doing this in the first place though- keyboard coming up on clicking an edit text is normal behavior. Making it come up on the second click is weird and confusing. The question you should be asking is how to fix the issue you're trying to solve with this work around. – Gabe Sechan Mar 07 '22 at 15:17
  • Maybe this can help: https://stackoverflow.com/a/19414316/636009 – David Conrad Mar 07 '22 at 15:43
  • @GabeSechan There are specific times in which clicking on the EditText do not allow the InputMethodManager to accept text. I would love for it to always accept text on first click. But the team I am working on believe that other tasks running at the same time cause this to happen occasionally. Also, I have tried the imm.hideSoftInputFromWindow(view.getWindowToken(), 0); command on pause, but there is always a crash, because of the application calling a null reference. Is there a way to do this even when the application is in the background? – RadioSam Mar 07 '22 at 17:01
  • @RadioSam There really aren't. If you found a way that that happens, I suggest you write up a detailed description of how, as you're likely doing something wrong. – Gabe Sechan Mar 07 '22 at 18:19

0 Answers0