material-components / material-components/material-components-android

[Component name]How to use activityoptions.makescenetransitionanimation after I use it, the animation effect is abnormal and the black screen flashes

Open
#2,443 8 comments 0 reactions 1 assignee View on GitHub

@hunterstich is already working on this.

Since Nov 2, 2021.

bug Feature: Transition
Dominant language
Java
Stars
17.4k
Forks
3.2k
PR merge metrics
No merged PRs in 30d

Description

**Description:**
this two actiivty ,i want from this actiivty launch another activity show anim
Effects like MusicPlayerDemoActivity,but my app not fragment! i try use material demo ,is work ,but my app flash blackscreen

However, an activity in the Material-component Demo also flashes a black screen
item is Transition/ launch Container Transform (Activity )
**Source code:**
```
public static void startNewActivityAnim(Activity activity,
Class activityTarget,
View v
) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// activity.setEnterSharedElementCallback(new MaterialContainerTransformSharedElementCallback());
activity.setExitSharedElementCallback(new MaterialContainerTransformSharedElementCallback());
activity.getWindow().setSharedElementsUseOverlay(false);
String shareName = activityTarget.getSimpleName();
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(activity, v, shareName);
Intent intent = new Intent(activity, activityTarget);
intent.putExtra("share_element",shareName);
activity.startActivity(intent, options.toBundle());
} else {
activity.startActivity(new Intent(activity, activityTarget));

}

}
```

```
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
View contentView = findViewById(android.R.id.content);
contentView.setTransitionName(share_element);
setEnterSharedElementCallback(new MaterialContainerTransformSharedElementCallback());

getWindow().setSharedElementEnterTransition(buildContainerTransform(/* entering= */ true, getThis(), contentView));
getWindow().setSharedElementReturnTransition(buildContainerTransform(/* entering= */ false, getThis(), contentView));
}
```
```

@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public static MaterialContainerTransform buildContainerTransform(boolean entering, Context context, View view) {
MaterialContainerTransform transform = new MaterialContainerTransform(context, entering);
transform.addTarget(android.R.id.content);
transform.setContainerColor(MaterialColors.getColor(view, R.attr.colorSurface));
transform.setFadeMode(MaterialContainerTransform.FADE_MODE_THROUGH);
return transform;
}

```

,use material componet add TestActivity, it work
```
package io.material.catalog.main;

import android.app.ActivityOptions;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentActivity;

import com.google.android.material.transition.platform.MaterialContainerTransformSharedElementCallback;

import io.material.catalog.R;
import io.material.catalog.feature.DemoActivity;
import io.material.catalog.musicplayer.MusicPlayerDemoActivity;

/**
* Author:Lozn
* Email:qssq521@gmail.com
* 2021/10/25
* 9:36
*/
public class TestActivity extends AppCompatActivity {

private View rootView;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_music);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
rootView = this.getWindow().getDecorView().findViewById(android.R.id.content);
// rootView.setTransitionName("test");
}

findViewById(R.id.tv_main).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(TestActivity.this, MainActivity.class);
startActivity(intent);
}
});
findViewById(R.id.tv_test).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(TestActivity.this, MusicPlayerDemoActivity.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Set up shared element transition and disable overlay so views don't show above system bars
FragmentActivity activity = TestActivity.this;
activity.setExitSharedElementCallback(new MaterialContainerTransformSharedElementCallback());
activity.getWindow().setSharedElementsUseOverlay(false);

ActivityOptions options =
ActivityOptions.makeSceneTransitionAnimation(activity, view, "test");
intent.putExtra(DemoActivity.EXTRA_TRANSITION_NAME, "test");
startActivity(intent, options.toBundle());

} else {
startActivity(intent);
}

}
});
}
}

```

**Android API version:** android 11 api 30

**Material Library version:** implementation 'com.google.android.material:material:1.5.0-alpha02'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.