Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transition blink after orientation change

UPDATE

Ive opened a bug with Google https://issuetracker.google.com/issues/63663775

I am attempting to employ makeSceneTransitionAnimation within my current Android Application.

I have a Source Activity, that contains a Fragment, and within the Fragment is a RecyclerView.

When I click on an image in the RecyclerView I transition to my Target Activity that contains a Fragment which correctly displays the image with an acceptable Animation.

Pressing the back button reverses the animation correctly.

The above works fine in both Portrait and Landscape orientation.

The issue of BLINKING occurs when I change orientation while viewing the target Fragment then press the Back Button.

There are other issues such as the image doesn't return directly to its original position, and on older devices I see horizontal lines like interference from an badly tuned analogue Television.

Its the BLINKING that is very bad, the device screen goes completely BLACK for approximately 500ms.

I have downloaded and deployed the google sample shared element transitions app and it appears to have the same "Feature".

I have tried multiple solutions and none of them have worked, such as this.

Here's a of the that exhibits the issue.

LOGCAT ADDED

07-21 12:57:18.097 1962-1967/com.incentive.yellowpages I/zygote64: Do partial code cache collection, code=30KB, data=21KB
07-21 12:57:18.099 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=30KB, data=23KB
07-21 12:57:18.099 1962-1967/com.incentive.yellowpages I/zygote64: Increasing code cache capacity to 128KB
07-21 12:57:20.540 1962-2058/com.incentive.yellowpages D/OkHttp: --> GET http://www.spyur.am/en/home/search-1/?company_name=Happy http/1.1
07-21 12:57:20.688 1962-1967/com.incentive.yellowpages I/zygote64: Do partial code cache collection, code=61KB, data=55KB
07-21 12:57:20.688 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=61KB, data=55KB
07-21 12:57:20.688 1962-1967/com.incentive.yellowpages I/zygote64: Increasing code cache capacity to 256KB
07-21 12:57:21.084 1962-2058/com.incentive.yellowpages D/OkHttp: <-- 200 OK http://www.spyur.am/en/home/search-1/?company_name=Happy (543ms, unknown-length body)
07-21 12:57:22.197 1962-1967/com.incentive.yellowpages I/zygote64: Do full code cache collection, code=124KB, data=93KB
07-21 12:57:22.197 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=98KB, data=59KB
07-21 12:57:22.377 1962-1967/com.incentive.yellowpages I/zygote64: Do partial code cache collection, code=101KB, data=79KB
07-21 12:57:22.378 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=101KB, data=79KB
07-21 12:57:22.378 1962-1967/com.incentive.yellowpages I/zygote64: Increasing code cache capacity to 512KB
07-21 12:57:22.378 1962-1967/com.incentive.yellowpages I/zygote64: Compiler allocated 4MB to compile boolean org.jsoup.parser.HtmlTreeBuilderState$7.process(org.jsoup.parser.Token, org.jsoup.parser.HtmlTreeBuilder)
07-21 12:57:22.701 1962-1967/com.incentive.yellowpages I/zygote64: Compiler allocated 4MB to compile void android.view.View.<init>(android.content.Context, android.util.AttributeSet, int, int)
07-21 12:57:24.495 1962-1967/com.incentive.yellowpages I/zygote64: Do full code cache collection, code=245KB, data=178KB
07-21 12:57:24.495 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=216KB, data=130KB
07-21 12:57:25.040 1962-2058/com.incentive.yellowpages D/OkHttp: --> GET http://www.spyur.am/en/companies/happy-print-printing-house/34896 http/1.1
07-21 12:57:25.101 1962-1962/com.incentive.yellowpages D/ViewRootImpl[DetailActivity]: changeCanvasOpacity: opaque=true
07-21 12:57:25.437 1962-2058/com.incentive.yellowpages D/OkHttp: <-- 200 OK http://www.spyur.am/en/companies/happy-print-printing-house/34896 (396ms, unknown-length body)
07-21 12:57:26.111 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 0
07-21 12:57:26.123 1962-1967/com.incentive.yellowpages I/zygote64: Do partial code cache collection, code=251KB, data=168KB
07-21 12:57:26.124 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=249KB, data=168KB
07-21 12:57:26.124 1962-1967/com.incentive.yellowpages I/zygote64: Increasing code cache capacity to 1024KB
07-21 12:57:26.173 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 1
07-21 12:57:26.177 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 2
07-21 12:57:26.186 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 3
07-21 12:57:26.226 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 4
07-21 12:57:26.232 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 5
07-21 12:57:26.238 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 6
07-21 12:57:26.244 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 7
07-21 12:57:26.265 1962-1967/com.incentive.yellowpages I/zygote64: Compiler allocated 8MB to compile void android.widget.TextView.<init>(android.content.Context, android.util.AttributeSet, int, int)
07-21 12:57:26.437 1962-1962/com.incentive.yellowpages D/ViewRootImpl[DetailActivity]: changeCanvasOpacity: opaque=false
07-21 12:57:26.579 1962-1967/com.incentive.yellowpages I/zygote64: Compiler allocated 6MB to compile void android.view.ViewRootImpl.performTraversals()
07-21 12:57:27.754 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 0
07-21 12:57:27.761 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 1
07-21 12:57:27.765 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 2
07-21 12:57:27.772 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 3
07-21 12:57:27.784 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 4
07-21 12:57:27.788 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 5
07-21 12:57:27.792 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 6
07-21 12:57:27.796 1962-1962/com.incentive.yellowpages I/DetailsAdapter: vvv: 7
07-21 12:57:29.889 1962-1962/com.incentive.yellowpages D/ViewRootImpl[DetailActivity]: changeCanvasOpacity: opaque=false
07-21 12:57:30.117 1962-1962/com.incentive.yellowpages D/ViewRootImpl[DetailActivity]: changeCanvasOpacity: opaque=false
07-21 12:57:30.756 1962-1962/com.incentive.yellowpages W/AutofillManager: Session 409360048 could not be restored
07-21 12:57:30.922 1962-1967/com.incentive.yellowpages I/zygote64: Do full code cache collection, code=498KB, data=362KB
07-21 12:57:30.923 1962-1967/com.incentive.yellowpages I/zygote64: After code cache collection, code=445KB, data=262KB
like image 383
Hector Avatar asked Jul 04 '17 14:07

Hector


3 Answers

Here's the problem: you are starting Activity2 in portrait mode and coming back to Activity1 in a landscape mode. But because you have performed orientation change, the view hierarchy of Activity1 is destroyed and created, thus the there is no more the View that originally the transition was started from.

What you can do, is to re-map the view from the old one to the new using Activity#setExitSharedElementCallback() API. There's a bit of work to do to handle that situation though, which I've already described step-by-step in my this answer.

The best choice for you would be to checkout Alex Lockwood's app at github with the functionality you need, it'll be much more easier for you to understand how to handle the situation.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setExitSharedElementCallback(new SharedElementCallback() {
        @Override
        public void onMapSharedElements(List<String> names, Map<String, View> sharedElements) {

            if (we are coming back to Activity1) {
                View newSharedElement = findViewById(R.id.your_imageview);
                if (newSharedElement != null) {
                    names.clear();
                    names.add("transition name");
                    sharedElements.clear();
                    sharedElements.put("transition name", newSharedElement);
                }
            } else {
                // we are leaving Activity1
            }
        }
    });
}

Basically, you are clearing the map and adding the new "transition name-view" pair to it. You can see how if (we are coming back to Activity1) check is being accomplished here.


Here's the feature, implemented in one of my apps.

enter image description here

like image 159
azizbekian Avatar answered Nov 16 '22 03:11

azizbekian


I think the problem is with the ImageView layoutbounds as scene transition calculates the difference between starting and end position and then animate the difference, but here the end position was changed due to orientation change, can you try and recreate the end layout as soon as you backpress in case of orientation change may be I'm wrong but can think of this scenario only, can you provide code for the same?(this was too big to add as a comment so have to add as an answer.)

like image 32
Ankit Khare Avatar answered Nov 16 '22 05:11

Ankit Khare


This seems to be occurring only on Oreo. It can be reproduced on an API 26 emulator using Google's sample project available here: https://github.com/googlesamples/android-ActivitySceneTransitionBasic/#readme

I managed to fix the problem in my app by adding this:

<item name="android:windowIsTranslucent">true</item>

To the style of my detail activity.

like image 1
Tim Autin Avatar answered Nov 16 '22 04:11

Tim Autin