0

On a button click, I want to go to an activity which is not written by me (such as ACTION_DIAL) and at the same time I want to control it's transition effects.

I am able to control transition effect at opening of the activity by using overridePendingTransition, but I am unable to control the transition effect when I come back to the same page by pressing the backbutton.

I want the same effect (android.R.anim.fade_in, android.R.anim.fade_out) to happen during start and finish of the activity, which is not happening as of now. It's working only at the start.

I am adding the code snippet below. Please have a look and help me out. :)

case R.id.button1:intent = new Intent(Intent.ACTION_DIAL);

                             startActivity(intent);
                             overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                             break;
case R.id.button2:intent = new Intent(Intent.ACTION_MAIN);
                             intent.addCategory(Intent.CATEGORY_APP_MESSAGING);
                            //intent.setType("vnd.android-dir/mms-sms");
                             startActivity(intent);
                             overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
                             break;
Sanoop Surendran
  • 3,484
  • 4
  • 28
  • 49
Arun K
  • 1
  • 2

2 Answers2

0

Try like this in your activity

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

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

or simply this

@Override
public void onBackPressed() {
   super.onBackPressed();
   overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
SaravInfern
  • 3,338
  • 1
  • 20
  • 44
0

Thank you SaravInfern for your help. But your solution won't help me because I am using the onBackPressed() function for doing some other operation.

However I was able to find solution myself, thanks to https://developer.android.com/training/basics/activity-lifecycle/stopping.html

I added the 'overridePendingTransition(R.anim.fade_in, R.anim.fade_out)' line inside onResume and onPause functions as follow which solved the issue for me.

@Override
public void onResume() {
    super.onResume();

    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);

}

@Override
public void onPause() {
    overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
    super.onPause();

}
Arun K
  • 1
  • 2