1

In my Activity I have an AutoCompleteTextView with a dropdown list. When the user selects an item, a new Activity is started. Since I have a lot of stuff in the next Activity, there's a delay of about 0.5-1s before it starts. I'm trying to hide the soft keyboard immediately after an item is selected:

   actvActionSearch.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View v,
                int position, long id) {
imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow(actvActionSearch.getWindowToken(), 0);
             //do stuff to prepare and start next Activity

        }
    });

However, the soft keyboard gets hidden appr. at the same time the next Activity starts. Where does this delay come from? Hiding the keyboard is the 1st thing I perform

Droidman
  • 10,609
  • 14
  • 85
  • 134

1 Answers1

2

Note how you are getting InputMethodManager as a system service?

That means your call to hideSoftInputFromWindow is performed on a system Service, which means its always running in the background along side of your app, which means when you hide keyboard, its actually running in parallel as your app which is performing the activity create.

wangyif2
  • 2,803
  • 2
  • 21
  • 29
  • does it matter that I actually initialize it in onCreate() and not in the method I posted above? If not, any solution to avoid this delay on keyboard close? – Droidman Sep 07 '13 at 18:45
  • What do you mean initialized it? One solution is to try to detect if the keyboard is shown before you launch your activity. See this post on how to detect keyboard: http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android – wangyif2 Sep 08 '13 at 17:57
  • I mean getting a reference to the corresponding system service: imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); – Droidman Sep 08 '13 at 18:05
  • It won't matter where you get the system service, when you call methods on background service, it will always be running seperately. – wangyif2 Sep 08 '13 at 18:13