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);
    }
}

解决方法

而不是Intent和NavUtils尝试使用onBackpressed()方法.
@Override
public boolean onoptionsItemSelected(MenuItem item) 
{
    // Handle item selection
    switch (item.getItemId()) 
    {
        case android.R.id.home:
            onBackpressed();
            return true;
        default:
            return super.onoptionsItemSelected(item);
    }
}

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...