Java Code Examples for android.support.v4.app.TaskStackBuilder#startActivities()

The following examples show how to use android.support.v4.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: MainActivity.java    From mobile-messaging-sdk-android with Apache License 2.0 6 votes vote down vote up
private void processDeepLink(Intent intent) {
    if (intent == null || intent.getData() == null) {
        return;
    }

    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
    List<String> segments = intent.getData().getPathSegments();
    if (segments.isEmpty()) {
        Intent launcherIntent = getPackageManager().getLaunchIntentForPackage(getPackageName());
        if (launcherIntent != null) {
            startActivity(launcherIntent.putExtras(intent));
        }
        return;
    }

    for (String segment : intent.getData().getPathSegments()) {
        if (activityMap.containsKey(segment)) {
            Intent nextIntent = new Intent(this, activityMap.get(segment)).putExtras(intent);
            stackBuilder.addNextIntent(nextIntent);
        }
    }
    stackBuilder.startActivities();
}
 
Example 2
Source File: BaseActivity.java    From privacy-friendly-passwordgenerator 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 3
Source File: BaseActivity.java    From privacy-friendly-torchlight 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: BaseActivity.java    From privacy-friendly-pin-mnemonic 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 5
Source File: BaseActivity.java    From privacy-friendly-qr-scanner 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 6
Source File: BaseActivity.java    From good-weather with GNU General Public License v3.0 5 votes vote down vote up
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 7
Source File: BaseActivity.java    From privacy-friendly-shopping-list with Apache License 2.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 8
Source File: BaseActivity.java    From RetailStore with Apache License 2.0 5 votes vote down vote up
/**
 * This utility method handles Up navigation intents by searching for a parent activity and
 * navigating there if defined. When using this for an activity make sure to define both the
 * native parentActivity as well as the AppCompat one when supporting API levels less than 16.
 * when the activity has a single parent activity. If the activity doesn't have a single parent
 * activity then don't define one and this method will use back button functionality. If "Up"
 * functionality is still desired for activities without parents then use
 * {@code syntheticParentActivity} to define one dynamically.
 * <p>
 * Note: Up navigation intents are represented by a back arrow in the top left of the Toolbar
 * in Material Design guidelines.
 *
 * @param currentActivity         Activity in use when navigate Up action occurred.
 * @param syntheticParentActivity Parent activity to use when one is not already configured.
 */
public static void navigateUpOrBack(Activity currentActivity,
                                    Class<? extends Activity> syntheticParentActivity) {
    // Retrieve parent activity from AndroidManifest.
    Intent intent = NavUtils.getParentActivityIntent(currentActivity);

    // Synthesize the parent activity when a natural one doesn't exist.
    if (intent == null && syntheticParentActivity != null) {
        try {
            intent = NavUtils.getParentActivityIntent(currentActivity, syntheticParentActivity);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
    }

    if (intent == null) {
        // No parent defined in manifest. This indicates the activity may be used by
        // in multiple flows throughout the app and doesn't have a strict parent. In
        // this case the navigation up button should act in the same manner as the
        // back button. This will result in users being forwarded back to other
        // applications if currentActivity was invoked from another application.
        currentActivity.onBackPressed();
    } else {
        if (NavUtils.shouldUpRecreateTask(currentActivity, intent)) {
            // Need to synthesize a backstack since currentActivity was probably invoked by a
            // different app. The preserves the "Up" functionality within the app according to
            // the activity hierarchy defined in AndroidManifest.xml via parentActivity
            // attributes.
            TaskStackBuilder builder = TaskStackBuilder.create(currentActivity);
            builder.addNextIntentWithParentStack(intent);
            builder.startActivities();
        } else {
            // Navigate normally to the manifest defined "Up" activity.
            NavUtils.navigateUpTo(currentActivity, intent);
        }
    }
}
 
Example 9
Source File: NavController.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Attempts to navigate up in the navigation hierarchy. Suitable for when the
 * user presses the "Up" button marked with a left (or start)-facing arrow in the upper left
 * (or starting) corner of the app UI.
 *
 * <p>The intended behavior of Up differs from {@link #popBackStack() Back} when the user
 * did not reach the current destination from the application's own task. e.g. if the user
 * is viewing a document or link in the current app in an activity hosted on another app's
 * task where the user clicked the link. In this case the current activity (determined by the
 * context used to create this NavController) will be {@link Activity#finish() finished} and
 * the user will be taken to an appropriate destination in this app on its own task.</p>
 *
 * @return true if navigation was successful, false otherwise
 */
public boolean navigateUp() {
    if (mBackStack.size() == 1) {
        // If there's only one entry, then we've deep linked into a specific destination
        // on another task so we need to find the parent and start our task from there
        NavDestination currentDestination = getCurrentDestination();
        int destId = currentDestination.getId();
        NavGraph parent = currentDestination.getParent();
        while (parent != null) {
            if (parent.getStartDestination() != destId) {
                TaskStackBuilder parentIntents = new NavDeepLinkBuilder(NavController.this)
                        .setDestination(parent.getId())
                        .createTaskStackBuilder();
                parentIntents.startActivities();
                if (mActivity != null) {
                    mActivity.finish();
                }
                return true;
            }
            destId = parent.getId();
            parent = parent.getParent();
        }
        // We're already at the startDestination of the graph so there's no 'Up' to go to
        return false;
    } else {
        return popBackStack();
    }
}
 
Example 10
Source File: BaseActivity.java    From privacy-friendly-weather 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 11
Source File: BaseActivity.java    From privacy-friendly-pedometer 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 12
Source File: BaseActivity.java    From privacy-friendly-ludo 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 13
Source File: BaseActivity.java    From privacy-friendly-dame 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 14
Source File: BaseActivity.java    From your-local-weather with GNU General Public License v3.0 5 votes vote down vote up
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 15
Source File: BaseActivity.java    From privacy-friendly-food-tracker 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 16
Source File: InAppChatImpl.java    From mobile-messaging-sdk-android with Apache License 2.0 4 votes vote down vote up
private void doCoreTappedActions(Message chatMessage) {
    TaskStackBuilder stackBuilder = stackBuilderForNotificationTap(chatMessage);
    if (stackBuilder.getIntentCount() != 0) {
        stackBuilder.startActivities();
    }
}
 
Example 17
Source File: BaseActivity.java    From privacy-friendly-netmonitor with GNU General Public License v3.0 2 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) {
    TaskStackBuilder builder = TaskStackBuilder.create(this);
    builder.addNextIntentWithParentStack(intent);
    builder.startActivities();
}