0

I have an ActionBarActivity "B" whose parent is ActionBarActivity "A" (also defined in manifest). A is in "singleTask" launch mode. I have an animation when starting B from A as follows:

public void onItemClick(...) {
    Intent mIntent = new Intent(getActivity(), B.class);
    startActivity(mIntent);
    getActivity().overridePendingTransition(R.anim.B_in, R.anim.A_out);
}

On B, I have the following onOptionsItemSelected and onBackPressed:

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == android.R.id.home) {
        getSupportFragmentManager().popBackStackImmediate();
        //onBackPressed();
        //finish();
    }
    return super.onOptionsItemSelected(item);
}

@Override
public void onBackPressed() {
    super.onBackPressed();
    overridePendingTransition(R.anim.A_in, R.anim.B_out);
}

Here is the problem: When I press back button, the animation at onBackPressed is taking place as expected. However, when I click on icon at top left in the actionbar, popBackStackImmediate is called and Android's default animation is played which is different. So:

  1. How can I manage to get same animation as in onBackPressed?
  2. Should I use onBackPressed() instead of popBackStackImmediate()? Will it give the same result as popBackStackImmediate do?

Any suggestions and best practices are welcome...

Mehmed
  • 2,880
  • 4
  • 41
  • 62

1 Answers1

2

You could use .popBackStack() instead of popBackStackImmediate() then overrride the pendingTransition, that might work. Since these are both activities though, my inclination would be to call finish(); then overridePendingTransition().

Dave S
  • 3,378
  • 1
  • 20
  • 34
  • Although I hesitate to call finish() in my code so far, I use finish()+overridePendingTransition() for this case. Thanks. – Mehmed Sep 18 '14 at 17:58