我正在为android编写应用程序,并且出现了一些问题。 我有主要的活动和设置活动。 我想从主要活动菜单开始设置活动。 我有这样的代码来做到这一点:从菜单中打开新的活动
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.menu_preferences:
Intent j = new Intent(getApplicationContext(), SettingsActivity.class);
startActivity(j);
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
但它无法正常工作。当我尝试它时,我有logcat:
Window already focused, ignoring focus gain of: [email protected]
而设置活动未显示。我不知道该怎么办...
似乎你在设置活动 –
谷歌的错误发布之前 – juned
问题是,我在主要活动。我改变了代码,像这样的答案,它不工作。我检查了按钮点击开始的活动。它可以工作,但代码是一样的。 – user2651180