Has anyone successfully used setExitTransition on L?
Asked Answered
T

3

7

I've been trying to use the new fancy animations that come with the L developer preview, but I'm having a lot of difficulties. In particular, I am not seeing any fancy animations. I'm trying to use the Explode exit transition. Here's the code:

public class ActivityA extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // inside your activity
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);

        // set an exit transition
        getWindow().setExitTransition(new Explode());
        setContentView(R.layout.activity_a);

        // Find our button and add our click handler
        Button button = (Button)findViewById(R.id.buttonA);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                // Transition to activity B
                Intent intent = new Intent(ActivityA.this, ActivityB.class);
                startActivity(intent);
            }
        });
    }
}
Thymic answered 23/7, 2014 at 14:48 Comment(0)
R
13

Instead of starting another activity using startActivity(intent); use the following statement.

startActivity(intent,ActivityOptions.makeSceneTransitionAnimation(this).toBundle());

I started another activity as said above and it worked for me.

It's said in google documentation Defining Custom Animations as follows.

enter image description here

Runesmith answered 24/4, 2015 at 12:29 Comment(0)
T
3

Solved the problem - you need the

getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);

call on the activity you are transitioning too as well!

Thymic answered 23/7, 2014 at 17:9 Comment(1)
Or just have your style inherit from Theme.Material.*** and you'll get this for free.Fan
C
0

Try this.

public class MyActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // enable transitions
        getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
        setContentView(R.layout.activity_my);
    }

    public void onSomeButtonClicked(View view) {
        getWindow().setExitTransition(new Explode());
        Intent intent = new Intent(this, MyOtherActivity.class);
        startActivity(intent,
                      ActivityOptions
                          .makeSceneTransitionAnimation(this).toBundle());
    }
}

requestFeature in onCreate an setExitTransition before startActivity

Chore answered 4/8, 2016 at 10:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.