Keyboard not closing after returning from email client

android, android-intent, android-softkeyboard

Solution

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);

Problem

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.

Original source