Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Animations and Transitions The Transitions Framework Transitioning Back and Forth

transitions back and forth 2

I'm still getting the same issue. What am I doing wrong? Am completely lost. Steve Hunter

MainActivity.java
public class MainActivity extends Activity {

    protected TransitionManager mTransitionManager;
    protected Scene mScene1;
    protected Scene mScene2;
    protected Scene mCurrentScene;
    protected TransitionSet mForwardSet;
    protected TransitionSet mBackwardSet;

    // Some code omitted for brevity

    public void onButtonClicked(View view) {
        if (mCurrentScene == mScene2) {
            mTransitionManager.transitionTo(mCurrentScene);
            mCurrentScene = mScene1;
        }
        else {
            mCurrentScene = mScene2;
        }

    }

    protected void setupTransitions() {
        // These methods are setting up scenes and transitions sets like in the video
        initScenes();
        initSets(); 

      TransitionManager transition = new TransitionManager();  // Start here!
      mTransitionManager.setTransition(mScene1, mScene2, mForwardSet);
      mTransitionManager.setTransition(mScene2, mScene1, mBackwardSet);  
      mScene1.enter(); 
    }
}

6 Answers

Yes, that's an incorrect solution that shouldn't pass the challenge.

The final task is Finally, fix the onButtonClicked() method so that the mTransitionManager successfully transitions to the new current scene when the button is tapped. - so your transitionTo() call must be within the onButtonClicked() method not setupTransitions().

So, add the line:

mTransitionManager.transitionTo(mCurrentScene);

within the onButtonClicked() method after the if statement. That's where it should be.

Steve.

OK - there is something else. You have set up a new TransitionManager - that needs to be called mTransitionManager. BUT it is already declared in the class at the top so don't redeclare it else you'll create a local variable that won't be available in other methods. So, drop the TranitionManager from the beginning as the class already knows that mTransitionManager is an instance of TransitionManager.

      mTransitionManager = new TransitionManager();  
      mTransitionManager.setTransition(mScene1, mScene2, mForwardSet);
      mTransitionManager.setTransition(mScene2, mScene1, mBackwardSet);  
      mScene1.enter(); 

Then put the call to transitionTo after the if statement inside the button clicked method.

I think if you're completely lost, as you say, it is probably best to go back through the video and understand what is going on here.

    public void onButtonClicked(View view) {
        if (mCurrentScene == mScene2) {
            mCurrentScene = mScene1;
        }
        else {
            mCurrentScene = mScene2;
            ;
        }
      mTransitionManager.transitionTo(mCurrentScene);
    }

The if statement has the effect of setting mCurrentScene to be the other scene, so if the current scene is mScene1 the if statement will make mCurrentScene be equal to mScene2, and vice versa. You then use transitionTo() to move over to mCurrentScene.

Hi Mal,

Isn't there a thread for this already?

Move the transitionTo call outside and after the if/else statement. There may be other issues but I'm not at my computer at the moment.

Steve.

Oh wait, that's what I did. Sooooo embarrased. I did put it after the if statement.

If you did do that; marking your copied answer as 'best' was a little disingenuous, right? As is deleting your answer.

Totally thought it was what I had written, that's why I didn't try to justify myself. Thanks for pointing out my mistake. I guess I'm a bit tired. I need to get some shut-eye.

Sleep sounds like a good plan. :smile: :+1:

LoL