編輯:已解決。下面單獨發佈答案Android鍵盤啓動後仍然可見電子郵件意圖
我正在啓動內置的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", "[email protected]", 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();
}
}
...
}
這是爲什麼這個工作?我需要了解並嘗試在我的情況下使用它。 – Poutrathor 2013-11-21 17:15:05