Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why overridePendingTransition does not take effect when I jump from Fragment to a new Activity?

The first activity contains a Fragment, and there's a button inside the fragment, and when I click this button, I wish to jump to a new Activity with different animation. So I do it like this in the Fragment:

          mButton.setOnClickListener(new OnClickListener() {
               @Override
               public void onClick(View v) {
                     Intent intent = new Intent(getActivity(), NewActivity.class);
                     getActivity().startActivity(intent);
                     getActivity().overridePendingTransition(
                           R.anim.forward_activity_move_in,
                           R.anim.forward_activity_move_out);
               });

However the new animation does not take effect when moves to the new Activity, so I wonder maybe I do it wrong. I hope someone can help me, thx a lot:)

like image 966
djj0809 Avatar asked Aug 21 '12 01:08

djj0809


People also ask

How to use myfragment via fragment transaction in Android?

When we press the FAB (Floating Action Button) button,we open the MyFragment via Fragment Transaction,attaching it to a FrameLayout we shall define. The Fragment contains an edittext and a spinner. User types the spacecraft name and chooses the launch year in the spinner. We then pass both these data back to MainActivity.

How does a fragmentmanager work internally?

Internally, the FragmentManager implementations iterates over a list and stops at the first occurrence of a fragment having such id. Now remember, “ A ” was added, removed. Hence the first and only occurrence here would be “ C “.

Is it possible to perform a popbackstack just before a fragment?

Others have tried to perform a popBackstack just before adding their own new fragment (causing a glitch on the monitor) The only solution i’ve found to work properly is to always add the transactions to the backstack and handle such “ A -> B -> C (back) -> A ” behavior by myself. For this reason i created a snippet that seems to work properly.

What are activities and fragments in Android?

Even though activities and fragments are nothing but classes, they are considered special classes in android since they are fundamental to how android User interface works. Thus we don’t just pass them data via constructors but in one of the following three ways: We will look at all these using practical examples in this lesson. Let’s start.


1 Answers

Thanks, I solved this problem, You can find solutions at Change activity transition when inside a TabHost

Well the problem is not the case of Fragment, instead the TabActivity causes the problem.

like image 128
djj0809 Avatar answered Nov 15 '22 00:11

djj0809