Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyboard not closing after returning from email client

I have an Android app that share a list of grocery over email. I have a trouble in which after I sent the list by email client (could be exchange client or Gmail client), the keyboard will not close.

I have tried:

InputMethodManager mgr = (InputMethodManager) getSystemService(
        Context.INPUT_METHOD_SERVICE);
mgr.hideSoftInputFromWindow(editTxt.getWindowToken(), 0);

and many other ways. If I check if the keyboard is open, it will return false since it is not the app that called the keyboard, but the email client.

I found a workaround including:

android:windowSoftInputMode="stateAlwaysHidden"

then the app will force closing the keyboard, but will continue lagging every time I open the keyboard again.

With Samsung phone the problem exists only if I use Gmail client.

like image 843
lagos Avatar asked Nov 03 '22 02:11

lagos


1 Answers

Found a solution. After some millisecond, the focus changed from outside the app (Email-client) to the editText view. Then I can close the keyboard. So my solution looks like this:

Timer timer = new Timer();
timer.schedule(new TimerTask() {

            @Override
            public void run() {
                closeKeyboard();
            }
        }, 20);
like image 73
lagos Avatar answered Nov 15 '22 00:11

lagos