[Component name]How to use activityoptions.makescenetransitionanimation after I use it, the animation effect is abnormal and the black screen flashes
See original GitHub issueDescription: 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’
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
makeSceneTransitionAnimation causes black screen after ...
A black screen is caused after using a shared element transition. This is how I reproduce this bug: Start the detail activity with...
Read more >Start an activity using an animation - Android Developers
When you enable activity transitions in your app, the default cross-fading transition is activated between the entering and exiting activities.
Read more >How to fix the Black screen render problem in Adobe Media ...
In this video tutorial I will show you how to fix the black screen problem in Adobe Media Encoder.Here I am using export...
Read more >Black Screen Appears in After Effects when Video is Paused ...
In this video I demonstrate how to fix an annoying after effects glitch where a black screen appears whenever you paused the video....
Read more >ActivityOptions Class (Android.App) | Microsoft Learn
Create an ActivityOptions specifying an animation where the new activity is scaled from a small originating area of the screen to its final...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Makes sense. I’ll keep the issue as opened and see if we can have a solution on the library side.
Well, there are many solutions:
MaterialContainerTransformSharedElementCallback#setTransparentWindowBackgroundEnabled(false)
Window#setSharedElementsUseOverlay(false)
Window#setTransitionBackgroundFadeDuration(transform.getDuration() + EXTRA_DURATION)
but it seems to me it’s too premature to close the issue:
TransitionContainerTransformStartDemoActivity
still doesn’t work correctlysetTransparentWindowBackgroundEnabled(true)
should work correctly, should it not?MaterialContainerTransformSharedElementCallback#setTransparentWindowBackgroundEnabled
doc)