Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android keyboard still visible after return from Email Activity

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 ();
    }
}
like image 629
wufoo Avatar asked Nov 03 '22 10:11

wufoo


1 Answers

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.

like image 72
wufoo Avatar answered Nov 11 '22 11:11

wufoo