public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main_screen, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_settings:
Intent Options = new Intent(this,
Options.class);
this.startActivity(Options);
break;
default:
return super.onOptionsItemSelected(item);
}
return true;
}
我的onOptionsItemSelected()沒有發送給我設置的活動。它只是踢我回到前一個屏幕。沒有錯誤或任何事情,只是踢我回屏幕?我已經在清單文件中聲明瞭Options.class。OnOptionsItemSelected()不發送到新的活動?
任何想法?
編輯:
Options.class
import android.app.Activity;
import android.os.Bundle;
public class Options extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.options);
}
}
main_screen.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_settings"
android:title="@string/menu_settings"
android:orderInCategory="100"
android:showAsAction="never" />
logcat的:只是將我的活動,然後回踢馬上
02-04 12:26:55.494: I/ActivityManager(150): Starting activity: Intent { cmp=com.app.test/.Options } from pid 7978
02-04 12:26:55.504: I/ActivityManager(150): Starting activity: Intent { cmp=com.app.test/.MainScreen (has extras) } from pid 7978
請爲option.class添加logcat,清單和代碼 –
'main_screen.xml'代碼可能是最有幫助的,你確定你的ID設置正確嗎? – iagreen
你可以發佈main_screen.xml嗎?您的Activity是否擴展了android.app.Activity或您自己的BaseActivity? –