5

I have an Activity (extending Activity) running in a TabHost. I launch the Android Email client from a user action. If I hit the "Discard" button in the Email client, the Email client exits but leaves the on-screen keyboard visible.

I have no EditTexts on my application so not sure why the keyboard stays up. I've tried several iterations of How do I remove the keyboard after I finish an activity? however no luck. Any thoughts?

code sample

package com.test.launchmail;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;

public class myEmail extends Activity
{
    private final String TAG = "** Email **";


    public static void send (Context ctx, String addy, String subject, String body)
    {
        // check to make sure the entry has a phone number
        try
        {
            // use the builtin chooser for users mail app
            Intent sendIntent = new Intent(Intent.ACTION_SEND);
            sendIntent.setType("text/plain");

            sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String [] {addy});
            sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
            sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, body);
            ctx.startActivity (Intent.createChooser(sendIntent, "Send via which Application?"));

        }
        catch (Exception e) 
        {
            Toast.makeText (ctx, "No activity was found to handle this action",Toast.LENGTH_SHORT).show();
        }
    }


    @Override
    protected void onPostResume()
    {
       // This executes, but keyboard still visible. 
        Log.d ("myEmail", "hiding");
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.hideSoftInputFromWindow (mainApp.tabHost.getCurrentTabView ().getApplicationWindowToken (),imm.HIDE_IMPLICIT_ONLY);

       super.onResume ();
    }
}
Community
  • 1
  • 1
wufoo
  • 10,915
  • 12
  • 49
  • 78

3 Answers3

2

Good grief how irritating. I searched around all day and finally found the answer buried under a thread of 29 different ways to do it. Everyone claiming success with a different variation of InputMethodManager. For what it's worth, this one worked for me Close/hide the Android Soft Keyboard.

It hope one day there is a standard API call to do this.

Community
  • 1
  • 1
wufoo
  • 10,915
  • 12
  • 49
  • 78
0

Try to put into your Manifest file in the desired activity (the one that you don't the keyboard to be shown) this: windowSoftInputMode="stateHidden"

Laura
  • 2,453
  • 6
  • 29
  • 54
0

My solution was to do the following before navigating to the email activity:

  1. make sure the keyboard was hidden on my app's screen (popular stackoverflow method used)
  2. and most importantly, make sure the EditText on the screen no longer had focus. contactSearchView.clearFocus()
jhavatar
  • 3,168
  • 1
  • 15
  • 11