Android custom transition from child to parent activity

I have 2 activities. Activitya is the parent activity of activityb:

My manifest file:

<activity
        android:name=".ActivityA"
        android:launchMode="singleTop" />
    <activity
        android:name=".ActivityB"
        android:parentActivityName=".ActivityA"/>

I have changed from activitya to activityb:

    final Intent intent = new Intent(this, ActivityB.class);
    startActivity(intent);
    overridePendingTransition(R.anim.push_left_in, R.anim.push_left_out);

Good, but now, I also want to change the transition from activityb to activitya. in my activityb, I override the finish () method like this:

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

The problem is that the finish () method is called only when the hardware back button is pressed, and the finish () method is not called when the back arrow (the upper left corner of the screen) is pressed

I also want a custom transition when I press the button

Any ideas?

resolvent:

You can do this by:

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case android.R.id.home:
                  finish();
                  overridePendingTransition(R.anim.push_right_in, R.anim.push_right_out);

        }
        return super.onOptionsItemSelected(item);
    }

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>