@Override protected void onStart() { super.onStart(); TaskStackBuilder.create(this) .addNextIntentWithParentStack(new Intent(this, MainActivity.class)) .addNextIntent(new Intent(this, IntroActivity.class)) .startActivities(); } }
stackBuilder.addParentStack(cls); stackBuilder.addNextIntent(activityIntent); stackBuilder.startActivities(); } else { activityIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // Respond to the action bar's Up/Home button case android.R.id.home: Intent upIntent = NavUtils.getParentActivityIntent(this); upIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); if (NavUtils.shouldUpRecreateTask(this, upIntent)) { // This activity is NOT part of this app's task, so create a new task // when navigating up, with a synthesized back stack. TaskStackBuilder.create(this) // Add all of this activity's parents to the back stack .addNextIntentWithParentStack(upIntent) // Navigate up to the closest parent .startActivities(); } else { // This activity is part of this app's task, so simply // navigate up to the logical parent activity. NavUtils.navigateUpTo(this, upIntent); } return true; } return super.onOptionsItemSelected(item); }
onCreateSupportNavigateUpTaskStack(b); onPrepareSupportNavigateUpTaskStack(b); b.startActivities();
public static void navigateUp(Activity activity, Bundle extras) { Intent upIntent = NavUtils.getParentActivityIntent(activity); if (upIntent != null) { if (extras != null) { upIntent.putExtras(extras); } if (NavUtils.shouldUpRecreateTask(activity, upIntent)) { // This activity is NOT part of this app's task, so create a new task // when navigating up, with a synthesized back stack. TaskStackBuilder.create(activity) // Add all of this activity's parents to the back stack. .addNextIntentWithParentStack(upIntent) // Navigate up to the closest parent. .startActivities(); } else { // This activity is part of this app's task, so simply // navigate up to the logical parent activity. // According to http://stackoverflow.com/a/14792752/2420519 //NavUtils.navigateUpTo(activity, upIntent); upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); activity.startActivity(upIntent); } } activity.finish(); }
/** * Start the task stack constructed by this builder. The Context used to obtain * this builder must be an Activity. * * <p>On devices that do not support API level 11 or higher the topmost activity * will be started as a new task. On devices that do support API level 11 or higher * the new task stack will be created in its entirety.</p> */ public void startActivities() { startActivities(null); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Bundle b = getIntent().getExtras(); fromNotification = b.getInt("fromNotification") == 1; setContentView(R.layout.threadlist); } @Override public boolean onHomeButtonPressed() { if(fromNotification) { // This activity is not part of the application's task, so create a new task // with a synthesized back stack. TaskStackBuilder tsb = TaskStackBuilder.from(this) .addNextIntent(new Intent(this, COPAme.class)); tsb.startActivities(); } // Otherwise, This activity is part of the application's task, so simply // navigate up to the hierarchical parent activity. finish(); return true; }
Intent activityInBackstack = new Intent(this, ActivityA.class); Intent activityToBeLaunched = new Intent(this, ActivityB.class); TaskStackBuilder builder = TaskStackBuilder.create(this); builder.addNextIntent(activityInBackstack); builder.addNextIntent(activityToBeLaunched); builder.startActivities();
TaskStackBuilder stack = TaskStackBuilder.create(context); Intent classAct = new Intent(context, ClassActivity.class); // This will clear any opened activities. Use if necessary classAct.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); Intent studentAct = new Intent(context, StudentActivity.class); studentAct.putExtra("exam_id", 123); stack.addNextIntent(home); stack.addNextIntent(studentAct); stack.addNextIntent(new Intent(context, StudentExamActivity.class)); stack.startActivities();
private void handlePreferenceThemeSelected() { TaskStackBuilder.create(activity) .addNextIntent(new Intent(activity, MainActivity.class)) .addNextIntent(activity.getIntent()) .startActivities(); }
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (key.equals(KEY_THEME)) { final Preference pref = fragment.findPreference(KEY_THEME); if (pref != null) { pref.setSummary(getCurrentThemeName()); } // Restart to apply new theme, go back to this settings screen TaskStackBuilder.create(this) .addNextIntent(new Intent(this, MainActivity.class)) .addNextIntent(this.getIntent()) .startActivities(); } }
/** Starts the Settings Activity if connection settings are missing * * @return true if setup was started */ private boolean startSetupIfNeeded(){ Preferences preferences = new Preferences(getApplicationContext()); if (TextUtils.isEmpty(preferences.getString(R.string.pref_key_host, null)) || preferences.getInt(R.string.pref_key_port, -1) == -1){ Intent settingsIntent = new Intent(this, SettingsActivity.class); settingsIntent.putExtra(SettingsActivity.EXTRA_SHOW_TOAST_KEY, SettingsActivity.EXTRA_SHOW_TOAST_SETUP_REQUIRED_FOR_QUICK_TILE); settingsIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // Use TaskStackBuilder to make sure the MainActivity opens when the SettingsActivity is closed TaskStackBuilder.create(this) .addNextIntentWithParentStack(settingsIntent) .startActivities(); Intent closeIntent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); sendBroadcast(closeIntent); return true; } return false; } }
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (themePrefKey.equals(key)) { // nice trick to recreate the back stack, to ensure existing activities onCreate() are // called to set new theme, courtesy of: http://stackoverflow.com/a/28799124/85472 TaskStackBuilder.create(getActivity()) .addNextIntent(new Intent(getActivity(), RepoListActivity.class)) .addNextIntent(getActivity().getIntent()) .startActivities(); } } };
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(); } }
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(); } }
/** * 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(); } }
/** * 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(); } }
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { if (themePrefKey.equals(key)) { // nice trick to recreate the back stack, to ensure existing activities onCreate() are // called to set new theme, courtesy of: http://stackoverflow.com/a/28799124/85472 TaskStackBuilder.create(getActivity()) .addNextIntent(new Intent(getActivity(), RepoListActivity.class)) .addNextIntent(getActivity().getIntent()) .startActivities(); } else if (gravatarPrefKey.equals(key)) { BasicFunctions.getImageLoader().clearMemoryCache(); BasicFunctions.getImageLoader().clearDiskCache(); } } };
private void goUp() { // Implementation of the up button from http://developer.android.com/training/implementing-navigation/ancestral.html // isTaskRoot() check works around a bug where pressing "up" does nothing when the viewer is launched // by tapping on a pdf download notification in the notification list. // see: http://stackoverflow.com/questions/19999619/navutils-navigateupto-does-not-start-any-activity Activity activity = getActivity(); Intent upIntent = NavUtils.getParentActivityIntent(activity); if (NavUtils.shouldUpRecreateTask(activity, upIntent) || activity.isTaskRoot()) { // e.g., this is the case when opening a pdf from the Downloads app and pressing the up button: // the ViewerActivity is running in the Downloads task, so the following will start a new task // to open the document-viewer library in. TaskStackBuilder.create(activity) .addNextIntentWithParentStack(upIntent) .startActivities(); getActivity().finish(); } else { // Restart the existing instance of the RecentActivity rather than starting a new one upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); NavUtils.navigateUpTo(activity, upIntent); } }
@Override public void onTrezorTaskCompletedSucc(String id, TrezorTaskResult res) { if (id.equals(TASK_RESET_DEVICE)) { if (res.getMsgResult().msgType == MessageType.MessageType_Success) { finish(); TaskStackBuilder taskStackBuilder = TaskStackBuilder.create(this); taskStackBuilder.addNextIntent(MainActivity.createIntent(this)); taskStackBuilder.addNextIntent(CreateBackupInitActivity.createIntent(this, CommonUtils.isTrezorV2(features))); taskStackBuilder.startActivities(); setDontDisconnectOnStop(); //startActivityNextStep(CreateBackupInitActivity.createIntent(this, CommonUtils.isTrezorV2(features))); } else if (res.getMsgResult().msgType == MessageType.MessageType_Failure) { showToastTrezorMsgFailure((Failure)res.getMsgResult().msg); refreshGui(); } else { onTrezorError(TrezorError.ERR_UNEXPECTED_RESPONSE); } } else throw new NotImplementedException(); } }