Search code examples
androidandroid-activityz-order

Set new Activity to be below current one


I am creating a custom transition animation between two activities. By default, the new Activity is above the current one.

Is it possible to make the new Activity to be below current Activity? And if it is possible, then How to implement this?


Solution

  • Not sure if this is the best practice but try this:

    In old activity:

    Intent newActivity = new Intent(this, NewActivity.class);
    startActivity(newActivity);
    

    Then in your new Activity:

    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.new_activity);
        Intent oldActivity= new Intent(this, OldActivity.class);
        oldActivity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(oldActivity);
    }