@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // Respond to the action bar's Up/Home button case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); }
@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); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (NavUtils.getParentActivityName(this) != null) { NavUtils.navigateUpFromSameTask(this); } return true; default: return super.onOptionsItemSelected(item); } } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: Intent intent = NavUtils.getParentActivityIntent(this); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP); NavUtils.navigateUpTo(this, intent); return true; } return super.onOptionsItemSelected(item); } private void exibirHotelFragment(Hotel hotel) {
/** * Navigate from sourceActivity to the activity specified by upIntent, finishing sourceActivity * in the process. upIntent will have the flag {@link android.content.Intent#FLAG_ACTIVITY_CLEAR_TOP} set * by this method, along with any others required for proper up navigation as outlined * in the Android Design Guide. * * <p>This method should be used when performing up navigation from within the same task * as the destination. If up navigation should cross tasks in some cases, see * {@link #supportShouldUpRecreateTask(android.content.Intent)}.</p> * * @param upIntent An intent representing the target destination for up navigation */ public void supportNavigateUpTo(Intent upIntent) { NavUtils.navigateUpTo(this, upIntent); }
/** * Obtain an {@link android.content.Intent} that will launch an explicit target activity * specified by sourceActivity's {@link android.support.v4.app.NavUtils#PARENT_ACTIVITY} <meta-data> * element in the application's manifest. If the device is running * Jellybean or newer, the android:parentActivityName attribute will be preferred * if it is present. * * @return a new Intent targeting the defined parent activity of sourceActivity */ @Override @Nullable public Intent getSupportParentActivityIntent() { return NavUtils.getParentActivityIntent(this); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: // This is called when the Home (Up) button is pressed in the action bar. // Create a simple intent that starts the hierarchical parent activity and // use NavUtils in the Support Package to ensure proper handling of Up. Intent upIntent = new Intent(this, MainActivity.class); if (NavUtils.shouldUpRecreateTask(this, upIntent)) { // This activity is not part of the application's task, so create a new task // with a synthesized back stack. TaskStackBuilder.from(this) // If there are ancestor activities, they should be added here. .addNextIntent(upIntent) .startActivities(); finish(); } else { // This activity is part of the application's task, so simply // navigate up to the hierarchical parent activity. NavUtils.navigateUpTo(this, upIntent); } return true; } return super.onOptionsItemSelected(item); }
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(); }
/** * 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 android.support.v4.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(Intent targetIntent) { return NavUtils.shouldUpRecreateTask(this, targetIntent); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: Intent intent = NavUtils.getParentActivityIntent(this); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP); NavUtils.navigateUpTo(this, intent); return true; } return super.onOptionsItemSelected(item); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case android.R.id.home: { Intent intent = new Intent(this, org.schabi.newpipe.MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); NavUtils.navigateUpTo(this, intent); return true; } default: return false; } } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (NavUtils.getParentActivityName(this) != null) { NavUtils.navigateUpFromSameTask(this); } return true; default: return super.onOptionsItemSelected(item); } } }
/** * Obtain an {@link android.content.Intent} that will launch an explicit target activity * specified by sourceActivity's {@link android.support.v4.app.NavUtils#PARENT_ACTIVITY} <meta-data> * element in the application's manifest. If the device is running * Jellybean or newer, the android:parentActivityName attribute will be preferred * if it is present. * * @return a new Intent targeting the defined parent activity of sourceActivity */ @Nullable @Override public Intent getSupportParentActivityIntent() { return NavUtils.getParentActivityIntent(this); }
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(); }
/** * 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 android.support.v4.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); }
@Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); // When the home button is pressed, take the user back to the VisualizerActivity if (id == android.R.id.home) { NavUtils.navigateUpFromSameTask(this); } return super.onOptionsItemSelected(item); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: Intent intent = NavUtils.getParentActivityIntent(this); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_SINGLE_TOP); NavUtils.navigateUpTo(this, intent); return true; } return super.onOptionsItemSelected(item); } private void exibirHotelFragment(Hotel hotel) {
@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); }
private void goToReturnActivity() { Class<? extends Activity> checkedReturnActivity = getReturnActivity(returnActivity); if (checkedReturnActivity == null) { super.onBackPressed(); } else { Intent intent = new Intent(this, checkedReturnActivity); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); NavUtils.navigateUpTo(this, intent); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: if (NavUtils.getParentActivityName(getActivity()) != null) { app.send(this, "Action", "Discard Todo"); makeResult(RESULT_CANCELED); NavUtils.navigateUpFromSameTask(getActivity()); } hideKeyboard(mToDoTextBodyEditText); return true; default: return super.onOptionsItemSelected(item); } }