question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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’

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
drchencommented, May 18, 2022

Makes sense. I’ll keep the issue as opened and see if we can have a solution on the library side.

0reactions
pubiqqcommented, May 18, 2022

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 correctly
  • setTransparentWindowBackgroundEnabled(true) should work correctly, should it not?
  • Shouldn’t the library take care of meeting this condition on its own? (from MaterialContainerTransformSharedElementCallback#setTransparentWindowBackgroundEnabled doc)

    Note: in order to avoid some visual artifacts, when this setting is enabled the window’s transition background fade duration (see Window.setTransitionBackgroundFadeDuration(long)) will be overridden to be greater than the duration of the transform transition.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found