编辑:解决。答案在下面单独发布
我正在启动内置的 Intent.ACTION_SEND “选择器”,以便用户可以选择如何从我的应用程序发送消息。它工作正常,但如果我在启动的电子邮件程序中点击“放弃”,它会返回到我的应用程序,屏幕键盘仍然可见。我尝试用各种 imm.hideSoftInputFromWindow (...) 咒语关闭它,但无济于事。任何想法如何解决这一问题?
这就是我启动“选择器”并尝试在 onActivityResult() 中关闭键盘的方式。请注意,tabHost 是我的主应用程序 (MainApp) 中的一个静态成员,它包含用于创建 tabSpecs 的 tabHost 对象。
public class L_Secondary extends ListActivity implements myConst
{
@Override
protected void onCreate (Bundle savedInstanceState)
{
super.onCreate (savedInstanceState);
setContentView(R.layout.l_people_secondary);
// instantiate the custom array adapter class and pass it some info to build a ListView with.
ListView lv = getListView ();
lv.setOnItemClickListener (oicl);
A_secondary da = new A_secondary (this, android.R.layout.simple_list_item_single_choice, mPiecesArray, mPartsArray);
setListAdapter (da);
}
...
// after launching the email client, the keyboard stays visible
// over the Listview. Currently the keyboard gets forced to close
// in getView() of the ArrayAdapter class da, in onCreate() above
public void launchEmail ()
{
try
{
// use the builtin chooser for users mail app
Intent sendIntent = new Intent(Intent.ACTION_SEND, Uri.fromParts ("mailto", "root@localhost", null));
sendIntent.setType("text/plain");
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "msg_subject");
sendIntent.putExtra(android.content.Intent.EXTRA_TEXT, "msg_body");
startActivityForResult (Intent.createChooser(sendIntent, "Send via which Application?"), 0);
}
catch (Exception e)
{
Toast.makeText (this, "No activity was found to handle this action",Toast.LENGTH_SHORT).show();
}
}
...
}