ホームボタンを「戻る」ボタンとして機能させるには、次のコードがあります。私が直面している問題は、実際のバックボタンを使用すると、単に前のアクティビティに戻ります。ホームボタンを使用すると、ページがリロードされるので、以前に行ったことは失われます。私はそれが私が行方不明の単純なものだと確信しています。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.census_management_search, menu);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
// Handle item selection
switch (item.getItemId())
{
case android.R.id.home:
Intent intent = new Intent(this, CensusManagementActivity.class);
NavUtils.navigateUpTo(this, intent);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
あなたの答えの両方働いていた、違いは何ですか? – Jhorra
['onBackPressed()'](http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.2.2_r1/android/app/)を呼び出すことをお勧めします。 Activity.java#Activity.onBackPressed%28%29)これはフラグメントのバックスタックをチェックし、空であれば 'finish()'を呼び出します。 – vasart
おかげさまでアクティビティを再ロードせずに完全に動作します。 –