Android: wrong jump when using navigateUpFromSameTask ()

I'm just starting out with Android, and I followed this tutorial on adding Up navigation to Activity in the action bar.

http://developer.android.com/training/implementing-navigation/ancestral.html

However, the transition, when I use the "up" button from the action bar, shows that this means a transition to the opening of a new activity, and not to a gradual disappearance, as happens when you click on the back at the bottom.

What can I do to display the correct transition? Thanks.

+7
android android-navigation
source share
7 answers

Declare android:launchMode="singleTop" inside your Manifest.xml for your parent activity.

Then the transition will change to the default when you call something like:

 @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { // Respond to the action bar Up/Home button case android.R.id.home: NavUtils.navigateUpFromSameTask(this); return true; } return super.onOptionsItemSelected(item); } 

(from: http://developer.android.com/training/implementing-navigation/ancestral.html#NavigateUp )

+13
source share

You should use the navigateUpTo () method and set the flag without animation to the intent, for example:

 final Intent intent = NavUtils.getParentActivityIntent(this); intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); NavUtils.navigateUpTo(this, intent); 

You will have a β€œgood” reverse animation and the correct use of the Up button. this is the current activity.

+9
source share

@Ciprian's solution works for me.

In addition, navigateUpFromSameTask() is just a convenience method equivalent to calling:

 final Intent intent = NavUtils.getParentActivityIntent(this); NavUtils.navigateUpTo(this, intent); 

When the Intent.FLAG_ACTIVITY_NO_ANIMATION flag is added, the transition from the disappearance of Intent.FLAG_ACTIVITY_NO_ANIMATION takes effect.

+1
source share

I fought a lot for the same problems and decided to solve it as follows:

  case android.R.id.home: onBackPressed(); return true; 

Whenever you press the back button onBackPressed() is called. Calling this when the back button of the action bar is pressed will do the same.

+1
source share

I changed it to the end (); and that seems to do what I want.

0
source share

This can be confusing as it was for me. However, my solution simply added android:launchMode="singleTop" to all parents, regardless of the parent who has another parent.

Hope this helps :)

0
source share

you can use the overridePendingTransition () method:

Call immediately after one of the options startActivity (Intent) or finish () to specify an explicit transition animation to perform the following.

http://developer.android.com/reference/android/app/Activity.html#overridePendingTransition(int , int)

-one
source share

All Articles