Example usage for android.app TaskStackBuilder startActivities

List of usage examples for android.app TaskStackBuilder startActivities

Introduction

In this page you can find the example usage for android.app TaskStackBuilder startActivities.

Prototype

public void startActivities() 

Source Link

Document

Start the task stack constructed by this builder.

Usage

From source file:android.app.Activity.java

/**
 * This method is called whenever the user chooses to navigate Up within your application's
 * activity hierarchy from the action bar.
 *
 * <p>If the attribute {@link android.R.attr#parentActivityName parentActivityName}
 * was specified in the manifest for this activity or an activity-alias to it,
 * default Up navigation will be handled automatically. If any activity
 * along the parent chain requires extra Intent arguments, the Activity subclass
 * should override the method {@link #onPrepareNavigateUpTaskStack(TaskStackBuilder)}
 * to supply those arguments.</p>/*from   w w  w.j ava2 s  .  c o  m*/
 *
 * <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 #getParentActivityIntent()}, {@link #shouldUpRecreateTask(Intent)}, and
 * {@link #navigateUpTo(Intent)} for help implementing custom Up navigation.
 * The AppNavigation sample application in the Android SDK is also available for reference.</p>
 *
 * @return true if Up navigation completed successfully and this Activity was finished,
 *         false otherwise.
 */
public boolean onNavigateUp() {
    // Automatically handle hierarchical Up navigation if the proper
    // metadata is available.
    Intent upIntent = getParentActivityIntent();
    if (upIntent != null) {
        if (mActivityInfo.taskAffinity == null) {
            // Activities with a null affinity are special; they really shouldn't
            // specify a parent activity intent in the first place. Just finish
            // the current activity and call it a day.
            finish();
        } else if (shouldUpRecreateTask(upIntent)) {
            TaskStackBuilder b = TaskStackBuilder.create(this);
            onCreateNavigateUpTaskStack(b);
            onPrepareNavigateUpTaskStack(b);
            b.startActivities();

            // We can't finishAffinity if we have a result.
            // Fall back and simply finish the current activity instead.
            if (mResultCode != RESULT_CANCELED || mResultData != null) {
                // Tell the developer what's going on to avoid hair-pulling.
                Log.i(TAG, "onNavigateUp only finishing topmost activity to return a result");
                finish();
            } else {
                finishAffinity();
            }
        } else {
            navigateUpTo(upIntent);
        }
        return true;
    }
    return false;
}