Java Code Examples for androidx.core.app.TaskStackBuilder#startActivities()

The following examples show how to use androidx.core.app.TaskStackBuilder#startActivities() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PostItemDetailActivity.java    From mimi-reader with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(View v) {
    // This ID represents the Home or Up button. In the case of this
    // activity, the Up button is shown. Use NavUtils to allow users
    // to navigate up one level in the application structure. For
    // more details, see the Navigation pattern on Android Design:
    //
    // http://developer.android.com/design/patterns/navigation.html#up-vs-back
    //
    final Intent listIntent = new Intent(this, PostItemListActivity.class);
    if (NavUtils.shouldUpRecreateTask(this, listIntent)) {
        final TaskStackBuilder taskStack = TaskStackBuilder.create(this);
        taskStack.addNextIntent(listIntent);
        taskStack.startActivities();
    } else {
        NavUtils.navigateUpTo(this, listIntent);
    }
}
 
Example 2
Source File: AppCompatPreferenceActivity.java    From MHViewer with Apache License 2.0 5 votes vote down vote up
/**
 * 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(androidx.core.app.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 androidx.core.app.TaskStackBuilder} class and the Activity methods
 * {@link #getSupportParentActivityIntent()}, {@link #supportShouldUpRecreateTask(android.content.Intent)}, and
 * {@link #supportNavigateUpTo(android.content.Intent)} for help implementing custom Up navigation.</p>
 *
 * @return true if Up navigation completed successfully and this Activity was finished,
 *         false otherwise.
 */
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;
}
 
Example 3
Source File: BaseActivity.java    From privacy-friendly-interval-timer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Enables back navigation for activities that are launched from the NavBar. See
 * {@code AndroidManifest.xml} to find out the parent activity names for each activity.
 * @param intent
 */
private void createBackStack(Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        TaskStackBuilder builder = TaskStackBuilder.create(this);
        builder.addNextIntentWithParentStack(intent);
        builder.startActivities();
    } else {
        startActivity(intent);
        finish();
    }
}
 
Example 4
Source File: AppCompatPreferenceActivity.java    From EhViewer with Apache License 2.0 5 votes vote down vote up
/**
 * 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(androidx.core.app.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 androidx.core.app.TaskStackBuilder} class and the Activity methods
 * {@link #getSupportParentActivityIntent()}, {@link #supportShouldUpRecreateTask(android.content.Intent)}, and
 * {@link #supportNavigateUpTo(android.content.Intent)} for help implementing custom Up navigation.</p>
 *
 * @return true if Up navigation completed successfully and this Activity was finished,
 *         false otherwise.
 */
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;
}