code: public boolean onSupportNavigateUp() {
          Intent upIntent = getSupportParentActivityIntent();
  
          if (upIntent != null) {
              if (supportShouldUpRecreateTask(upIntent)) {
                  TaskStackBuilder b = TaskStackBuilder.create(this);
                  onCreateSupportNavigateUpTaskStack(b);
                  onPrepareSupportNavigateUpTaskStack(b);
                  b.startActivities();
  
                  try {
                      ActivityCompat.finishAffinity(this);
                  } catch (IllegalStateException e) {
                      // This can only happen on 4.1+, when we don't have a parent or a result set.
                      // In that case we should just finish().
                      finish();
                  }
              } else {
                  // This activity is part of the application's task, so simply
                  // navigate up to the hierarchical parent activity.
                  supportNavigateUpTo(upIntent);
              }
              return true;
          }
          return false;
      }
docs: This method is called whenever the user chooses to navigate Up within your application's
  activity hierarchy from the action bar.
  
  <p>If a parent was specified in the manifest for this activity or an activity-alias to it,
  default Up navigation will be handled automatically. See
  {@link #getSupportParentActivityIntent()} for how to specify the parent. If any activity
  along the parent chain requires extra Intent arguments, the Activity subclass
  should override the method {@link #onPrepareSupportNavigateUpTaskStack(TaskStackBuilder)}
  to supply those arguments.</p>
  
  <p>See <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and
  Back Stack</a> from the developer guide and
  <a href="{@docRoot}design/patterns/navigation.html">Navigation</a> from the design guide
  for more information about navigating within your app.</p>
  
  <p>See the {@link TaskStackBuilder} class and the Activity methods
  {@link #getSupportParentActivityIntent()}, {@link #supportShouldUpRecreateTask(Intent)}, and
  {@link #supportNavigateUpTo(Intent)} for help implementing custom Up navigation.</p>
  
  @return true if Up navigation completed successfully and this Activity was finished,
  false otherwise.