Hide soft keyboard showed by other application

735 views Asked by At

I know that to hide soft keyboard I need to use code like this:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

My problem is that I starting the ACTION_SEND intent, and use Twitter app to handle it. I pass a message to tweet it. But if the user does not confirm the message, but clicks ActionBar back button, the Twitter activity is finished, and my app lication comes back to the front. But the soft Keyboard, called by Twitter does not hide. I have no idea how to get Twitter's WindowToken. Could anybody help me?

2

There are 2 answers

0
Vladyslav Matviienko On BEST ANSWER

I have found an unswer. I had to add this code:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

in the onResume() method

0
Alex P On

Another way is to do the same in AndroidManifest.xml file. You can annotate your activity with the following line:

android:windowSoftInputMode="stateAlwaysHidden"

which means your activity will always hide keyboard when receives focus.