0

I want to implement slide up & down animation when an activity is pushed to / off stack. Here is my code:

public class LoginActivity extends ActionBarActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        overridePendingTransition(R.anim.slide_up, R.anim.nothing);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        Button loginBtn = (Button)findViewById(R.id.login);
        loginBtn.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            finish();
          }
        });

    }

    @Override
    public void onBackPressed() {
        finish();
    }

    @Override
    public void finish() {
        overridePendingTransition(R.anim.nothing, R.anim.slide_down);
        super.finish();
    }
}

The activity is started via "startActivityForResult()) method. The theme for this activity is "Theme.AppCompat.Light.NoActionBar".

Here is the problem:
The animation for launching activity works.
When pressed "back" button, the slide-down animation also works.
However, when I call "finish()" directly within the activity to close it, the animation does notwork.

What's the problem? How to fix it?

Hua Hou
  • 91
  • 7

2 Answers2

0

You can override a pending transition just calling after finish();

finish();
LoginActivity.this.overridePendingTransition(R.anim.nothing,R.anim.nothing);

P.S. Answer was taken from here How can I add an animation to the activity finish()

Community
  • 1
  • 1
Anatol
  • 941
  • 1
  • 7
  • 13
0

Using finishAfterTransition() instead of finish() solved the issue for me. I think it is a cleaner solution than overriding the transition.

The Squake
  • 13
  • 3