单击工具栏的后退按钮时不会关闭活动

oja*_*jas 5 android android-toolbar

参考下图, 在此输入图像描述
我想回到之前的活动.
但是点击工具栏上的后退按钮,什么也没发生.
我使用以下代码来实现仍然没有运气.

public boolean onOptionsItemSelected(MenuItem item){
       if(item.getItemId() == R.id.home)
       {
           finish();
       }
      return true;
    }
Run Code Online (Sandbox Code Playgroud)

Htm*_*sin 14

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();
        switch (id) {
            // Respond to the action bar's Up/Home button
            case android.R.id.home:
                //NavUtils.navigateUpFromSameTask(this);
                onBackPressed();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
Run Code Online (Sandbox Code Playgroud)