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 ();
}
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With