crash - material design android 5.0

As I still need to support everything down to Android version 9, neither android:transitionGroup="true" nor using TransitionListener would work for me. I could prevent the problem by disabling hardware acceleration on Activity level:

<activity android:hardwareAccelerated="false" />

Disabling it on a view level didn't work for me, but might work for others:

myView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

If you take a look at your logs, immediately above the stack trace you'll probably see a warning similar to:

W/OpenGLRenderer﹕ Layer exceeds max. dimensions supported by the GPU (1080x5856, max=4096x4096)

Scene animations work by creating a bitmap layer of the target scene. The GPU has a maximum capacity for this layer. On a Nexus 5 this is 4096x4096. Your target scene has views in it which result in a layer which is too large, probably due to the large amounts of text content. This exceeds the capacity of the GPU causing the app to crash. The reason why this doesn't occur on the emulator is because the host GPU has a greater memory.

Solution

Avoid creating a target layer which is higher than 4096 before the transition animation ends. Instead load your content after the transition ends. You can listen for the transition ended event by implementing the TransitionListener interface. An example of this can be found here. You can then load your content.


The best solution as it was pointed out in other answers is to add: android:transitionGroup="true" to the long view (usually ScrollView of some kind).

As for the transition listener approach, don't forget to re-create your view on rotation when there were no shared animations.

Tags:

Android

Crash