在我的应用程序中,用户应该能够点击操作栏上的应用程序图标以返回到第一个活动。我试图实现以下代码,但它似乎不起作用。有人有什么建议可以让它工作吗?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.result_details);
ActionBar actionBar = getActionBar();
actionBar.show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
new MenuInflater(this).inflate(R.layout.menu, menu);
return (super.onCreateOptionsMenu(menu));
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent intent = new Intent(this, First.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
return true;
case R.id.feedback:
Intent intent1 = new Intent(ResultDetails.this.getApplicationContext(), feedback.class);
ResultDetails.this.startActivity(intent1);
return (true);
case R.id.about:
Intent intent2 = new Intent(ResultDetails.this.getApplicationContext(), about.class);
ResultDetails.this.startActivity(intent2);
return (true);
}
return (super.onOptionsItemSelected(item));
}