Example usage for android.support.v4.app TaskStackBuilder startActivities

List of usage examples for android.support.v4.app TaskStackBuilder startActivities

Introduction

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

Prototype

public void startActivities() 

Source Link

Document

Start the task stack constructed by this builder.

Usage

From source file:Main.java

/**
 * 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/*  ww w  . j  a v  a  2  s  .com*/
 */
public static void createBackStack(Activity activity, Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        TaskStackBuilder builder = TaskStackBuilder.create(activity);
        builder.addNextIntentWithParentStack(intent);
        builder.startActivities();
    } else {
        activity.startActivity(intent);
        activity.finish();
    }
}

From source file:at.ac.tuwien.caa.docscan.ActivityUtils.java

/**
 * 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/*from  w w w.jav a2  s  .  co  m*/
 */
public static void createBackStack(Activity activity, Intent intent) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        TaskStackBuilder builder = TaskStackBuilder.create(activity);
        builder.addNextIntentWithParentStack(intent);
        builder.startActivities();
    } else {
        activity.startActivity(intent);
        activity.finish();
    }

    //        Use our own animation - instead of the default scaling animation:
    activity.overridePendingTransition(R.anim.translate_in, R.anim.translate_out);
}

From source file:task.application.com.colette.util.ActivityUtils.java

/**
 * 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//from  w w w  . j a  v  a 2s .c  o  m
 */
public static void createBackStack(Activity activity, Intent intent) {
    TaskStackBuilder builder = TaskStackBuilder.create(activity);
    builder.addNextIntentWithParentStack(intent);
    builder.startActivities();
}

From source file:com.crazymin2.retailstore.ui.BaseActivity.java

/**
 * 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>/*from  w  w  w . j a v  a 2s.c om*/
 * 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);
        }
    }
}

From source file:ru.yandex.subtitles.ui.appwidget.AbstractAppWidget.java

private void startConversation(final Context context, final Intent intent) {
    final int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);
    final String phrase = intent.getStringExtra(Intent.EXTRA_TEXT);

    if (TextUtilsExt.isEmpty(phrase)) {
        Analytics.onAppWidgetStartConversationClick();
    } else {//w  w w .  ja v a 2 s .com
        Analytics.onAppWidgetPhraseClick(phrase);
    }

    final Intent mainIntent = QuickStartActivity.createStartIntent(context);
    final Intent conversationIntent = ConversationActivity.createStartConversationIntent(context, appWidgetId,
            phrase);

    final TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addNextIntent(mainIntent);
    stackBuilder.addNextIntent(conversationIntent);
    stackBuilder.startActivities();
}

From source file:com.g11x.checklistapp.NavigationActivity.java

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 {/* w  w w  .  j  a v  a2 s  . c  o  m*/
        startActivity(intent);
        finish();
    }
}

From source file:com.aetoslabs.quickfacts.AppCompatPreferenceActivity.java

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();/*from   w ww .j a  v  a2  s.  com*/
            }
        } 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;
}

From source file:com.nogago.android.tracks.ImportActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_PROGRESS_ID:
        progressDialog = DialogUtils.createHorizontalProgressDialog(this,
                R.string.sd_card_import_progress_message, new DialogInterface.OnCancelListener() {
                    @Override//from  w w  w.ja v  a 2s .  co m
                    public void onCancel(DialogInterface dialog) {
                        importAsyncTask.cancel(true);
                        finish();
                    }
                });
        return progressDialog;
    case DIALOG_RESULT_ID:
        String message;
        if (successCount == 0) {
            message = getString(R.string.sd_card_import_error_no_file, path);
        } else {
            String totalFiles = getResources().getQuantityString(R.plurals.importGpxFiles, totalCount,
                    totalCount);
            message = getString(R.string.sd_card_import_success_count, successCount, totalFiles, path);
        }
        return new AlertDialog.Builder(this).setCancelable(true).setMessage(message)
                .setOnCancelListener(new DialogInterface.OnCancelListener() {
                    @Override
                    public void onCancel(DialogInterface dialog) {
                        finish();
                    }
                }).setPositiveButton(R.string.generic_ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (!importAll && trackId != -1L) {
                            Intent intent = IntentUtils
                                    .newIntent(ImportActivity.this, TrackDetailActivity.class)
                                    .putExtra(TrackDetailActivity.EXTRA_TRACK_ID, trackId);
                            TaskStackBuilder taskStackBuilder = TaskStackBuilder.from(ImportActivity.this);
                            taskStackBuilder.addNextIntent(intent);
                            taskStackBuilder.startActivities();
                        }
                        finish();
                    }
                }).create();
    default:
        return null;
    }
}

From source file:pl.kodujdlapolski.na4lapy.ui.splash.SplashActivity.java

public void goToBrowse() {
    TaskStackBuilder b = TaskStackBuilder.create(this);
    Intent browse = new Intent(SplashActivity.this, SingleBrowseActivity.class);
    b.addNextIntent(browse);/*  w ww.  j a  v a 2s  .  c  o m*/
    if (preferencesService.shouldIntroductionBeShown()) {
        Intent intent1 = new Intent(this, IntroductionActivity.class);
        b.addNextIntent(intent1);
    }
    b.startActivities();
    finish();
}

From source file:com.conferenceengineer.android.iosched.ui.TaskStackBuilderProxyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TaskStackBuilder builder = TaskStackBuilder.create(this);
    Intent proxyIntent = getIntent();//from   ww w.  j a  v  a 2 s  .com
    if (!proxyIntent.hasExtra(EXTRA_INTENTS)) {
        finish();
        return;
    }

    for (Parcelable parcelable : proxyIntent.getParcelableArrayExtra(EXTRA_INTENTS)) {
        builder.addNextIntent((Intent) parcelable);
    }

    builder.startActivities();
    finish();
}