/** * 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()) { // 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); }
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(); }
/** * 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); }
@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) { 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()) { 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()) { 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()) { 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()) { 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) {
/** * Add the activity parent chain as specified by manifest <meta-data> elements * to the task stack builder. * * @param sourceActivity All parents of this activity will be added * @return This TaskStackBuilder for method chaining */ public TaskStackBuilder addParentStack(Activity sourceActivity) { final int insertAt = mIntents.size(); Intent parent = NavUtils.getParentActivityIntent(sourceActivity); while (parent != null) { mIntents.add(insertAt, parent); try { parent = NavUtils.getParentActivityIntent(sourceActivity, parent.getComponent()); } catch (NameNotFoundException e) { Log.e(TAG, "Bad ComponentName while traversing activity parent metadata"); throw new IllegalArgumentException(e); } } return this; }
/** * Add the activity parent chain as specified by manifest <meta-data> elements * to the task stack builder. * * @param sourceActivityClass All parents of this activity will be added * @return This TaskStackBuilder for method chaining */ public TaskStackBuilder addParentStack(Class<?> sourceActivityClass) { final int insertAt = mIntents.size(); try { Intent parent = NavUtils.getParentActivityIntent(mSourceContext, sourceActivityClass); while (parent != null) { mIntents.add(insertAt, parent); parent = NavUtils.getParentActivityIntent(mSourceContext, parent.getComponent()); } } catch (NameNotFoundException e) { Log.e(TAG, "Bad ComponentName while traversing activity parent metadata"); throw new IllegalArgumentException(e); } return this; }
/** * Add the activity parent chain as specified by manifest <meta-data> elements * to the task stack builder. * * @param sourceActivityName Must specify an Activity component. All parents of * this activity will be added * @return This TaskStackBuilder for method chaining */ public TaskStackBuilder addParentStack(ComponentName sourceActivityName) { final int insertAt = mIntents.size(); try { Intent parent = NavUtils.getParentActivityIntent(mSourceContext, sourceActivityName); while (parent != null) { mIntents.add(insertAt, parent); parent = NavUtils.getParentActivityIntent(mSourceContext, parent.getComponent()); } } catch (NameNotFoundException e) { Log.e(TAG, "Bad ComponentName while traversing activity parent metadata"); throw new IllegalArgumentException(e); } return this; }
/** * Convenience method that is equivalent to calling * <code>{@link #navigateUpTo(Activity, Intent) navigateUpTo}(sourceActivity, * {@link #getParentActivityIntent(Activity) getParentActivityIntent} (sourceActivity))</code>. * sourceActivity will be finished by this call. * * <p><em>Note:</em> This method should only be used when sourceActivity and the corresponding * parent are within the same task. If up navigation should cross tasks in some cases, see * {@link #shouldUpRecreateTask(Activity, Intent)}.</p> * * @param sourceActivity The current activity from which the user is attempting to navigate up */ public static void navigateUpFromSameTask(Activity sourceActivity) { Intent upIntent = getParentActivityIntent(sourceActivity); if (upIntent == null) { throw new IllegalArgumentException("Activity " + sourceActivity.getClass().getSimpleName() + " does not have a parent activity name specified." + " (Did you forget to add the android.support.PARENT_ACTIVITY <meta-data> " + " element in your manifest?)"); } navigateUpTo(sourceActivity, upIntent); }
@Override protected void onDestroy() { super.onDestroy(); Intent intent = new Intent(this,controlWidgetProvider.class); intent.setAction("android.appwidget.action.APPWIDGET_UPDATE"); int[] ids = {R.xml.control_appwidget_info}; intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,ids); sendBroadcast(intent); startActivity(NavUtils.getParentActivityIntent(this)); } }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: Intent intent = NavUtils.getParentActivityIntent(getActivity()); intent.putExtra("carro", carro); NavUtils.navigateUpTo(getActivity(), intent); return true; } return super.onOptionsItemSelected(item); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: Intent intent = NavUtils.getParentActivityIntent(getActivity()); intent.putExtra("carro", carro); NavUtils.navigateUpTo(getActivity(), intent); 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(); }
@SuppressWarnings("deprecation") @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case android.R.id.home: Intent i = NavUtils.getParentActivityIntent(this); NavUtils.navigateUpTo(this, i); return true; case R.id.menu_edit_app: editApp(); return true; case R.id.menu_copy_app: copyApp(); return true; case R.id.menu_delete_app: showDialog(DIALOG_CONFIRM_DELETE); return true; case R.id.menu_select_app: selectApp(); return true; } return super.onOptionsItemSelected(item); }
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); } }