0

If I start a new project in Android Studio v2.1.2 and add a second activity so I have two, when I switch activities there is no slide animation. When I try to search for answers, it looks like the slide animation is the default, so I don't understand why it's not sliding. Instead, the second activity is instantly displayed with no animation. I'm switching activities like this:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
        case R.id.goToMain:
            return true;
        case R.id.goToSecond:
            goToSecond();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

public void goToSecond(){
    Intent intent = new Intent(this, SecondActivity.class);
    startActivity(intent);
}

I know it's not critical, but it might add some flare. I have tried a lot of things and cannot find a way to make this work. For instance, everything I could find in the android developer training is for a higher API level. I'm using a min API level of 15, because that matches the level on my phone.

It looks like what I'm looking for might also be called a transition, but whatever it's called I'd just like to know why the slide animation is not happening. How can I add it?

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
Brian Gottier
  • 4,522
  • 3
  • 21
  • 37
  • 3
    Default animation is actually system dependent. Also the phone can actually turn animations off. – DeeV Aug 05 '16 at 22:54
  • @DeeV, the animations are turned on (x1) when I go to developer options. Would the phone just turn off animations by itself for a reason? – Brian Gottier Aug 05 '16 at 23:52

1 Answers1

0

According to this Answer, use

overridePendingTransition(R.anim.enterAnimation, R.anim.exitAnimation);

to make an activity do a specific transition effect. what's cooler is, you can use this approach in diferent events, like for starting a new activity you would do overrideTransition to make it slide to the right, however, for getting back from an activty (onBackPressed or similar events) you can make it slide to the left, I think this would add the flare you're talking about.

Hope this helps :)

Edit: And yes like @Deev said, animation is maily controlled from the settings of the device itself.

Community
  • 1
  • 1
Ahmed Ashraf
  • 2,795
  • 16
  • 25
  • I had already found this answer in multiple places, but it didn't work for me, so I guess it must be that DeeV is the one that is right. – Brian Gottier Aug 05 '16 at 23:39