Java Code Examples for androidx.core.app.NavUtils#shouldUpRecreateTask()
The following examples show how to use
androidx.core.app.NavUtils#shouldUpRecreateTask() .
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: FeedActivity.java From android-mvvm-architecture with Apache License 2.0 | 6 votes |
@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); }
Example 2
Source File: PostItemDetailActivity.java From mimi-reader with Apache License 2.0 | 6 votes |
@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 3
Source File: AppUtils.java From MaterialProgressBar with Apache License 2.0 | 6 votes |
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(); }
Example 4
Source File: DetailFragment.java From wear-os-samples with Apache License 2.0 | 5 votes |
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // Some small additions to handle "up" navigation correctly Intent upIntent = NavUtils.getParentActivityIntent(getActivity()); upIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); // Check if up activity needs to be created (usually when // detail screen is opened from a notification or from the // Wearable app if (NavUtils.shouldUpRecreateTask(getActivity(), upIntent) || getActivity().isTaskRoot()) { // Synthesize parent stack TaskStackBuilder.create(getActivity()) .addNextIntentWithParentStack(upIntent) .startActivities(); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { // On Lollipop+ we finish so to run the nice animation getActivity().finishAfterTransition(); return true; } // Otherwise let the system handle navigating "up" return false; } return super.onOptionsItemSelected(item); }
Example 5
Source File: ExperimentDetailsFragment.java From science-journal with Apache License 2.0 | 5 votes |
private void goToExperimentList() { if (getActivity() == null) { if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "goToExperimentList called on null activity"); } return; } if (claimExperimentsMode) { getActivity().finish(); return; } Intent upIntent = getActivity() == null ? null : NavUtils.getParentActivityIntent(getActivity()); if (upIntent == null) { // This is cheating a bit. Currently, upIntent has only been observed to be null // when we're using panes mode, so here we just assume usePanes==true. Intent intent = MainActivity.launchIntent(getActivity(), R.id.navigation_item_experiments, true); getActivity().startActivity(intent); getActivity().finish(); return; } if (NavUtils.shouldUpRecreateTask(getActivity(), upIntent) || getArguments().getBoolean(ARG_CREATE_TASK, false)) { upIntent.putExtra(MainActivity.ARG_SELECTED_NAV_ITEM_ID, R.id.navigation_item_experiments); upIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP); // TODO: Transition animation TaskStackBuilder.create(getActivity()) .addNextIntentWithParentStack(upIntent) .startActivities(); } else { NavUtils.navigateUpTo(getActivity(), upIntent); } }
Example 6
Source File: AppCompatPreferenceActivity.java From MHViewer with Apache License 2.0 | 2 votes |
/** * Returns true if sourceActivity should recreate the task when navigating 'up' * by using targetIntent. * * <p>If this method returns false the app can trivially call * {@link #supportNavigateUpTo(android.content.Intent)} using the same parameters to correctly perform * up navigation. If this method returns false, the app should synthesize a new task stack * by using {@link androidx.core.app.TaskStackBuilder} or another similar mechanism to perform up navigation.</p> * * @param targetIntent An intent representing the target destination for up navigation * @return true if navigating up should recreate a new task stack, false if the same task * should be used for the destination */ public boolean supportShouldUpRecreateTask(@NonNull Intent targetIntent) { return NavUtils.shouldUpRecreateTask(this, targetIntent); }
Example 7
Source File: AppCompatPreferenceActivity.java From EhViewer with Apache License 2.0 | 2 votes |
/** * Returns true if sourceActivity should recreate the task when navigating 'up' * by using targetIntent. * * <p>If this method returns false the app can trivially call * {@link #supportNavigateUpTo(android.content.Intent)} using the same parameters to correctly perform * up navigation. If this method returns false, the app should synthesize a new task stack * by using {@link androidx.core.app.TaskStackBuilder} or another similar mechanism to perform up navigation.</p> * * @param targetIntent An intent representing the target destination for up navigation * @return true if navigating up should recreate a new task stack, false if the same task * should be used for the destination */ public boolean supportShouldUpRecreateTask(@NonNull Intent targetIntent) { return NavUtils.shouldUpRecreateTask(this, targetIntent); }