Skip to content

ActivityFrameTracker breaks runtime theme changing. #1659

Closed
@kaneoriley

Description

@kaneoriley

Platform:

  • Android -> If yes, which Device API (and compileSdkVersion/targetSdkVersion/Build tools) version?
  • Java -> If yes, which Java (and sourceCompatibility/targetCompatibility) version?
  • Kotlin -> If yes, which Kotlin (and jvmTarget) version?
  • NDK -> If yes, which NDK/CMake version?
  • React-Native -> If yes, which version?
  • Timber -> If yes, which version?
  • Log4j2 -> If yes, which version?
  • Logback -> If yes, which version?
  • Spring -> If yes, which version?

IDE:

  • Android Studio -> If yes, which version?
  • IntelliJ -> If yes, which version?
  • Other -> If yes, which one?

Build system:

  • Gradle -> If yes, which version?
  • Buck -> If yes, which version?
  • Bazel -> If yes, which version?
  • Maven -> If yes, which version?
  • Other -> If yes, which one?

Android Gradle Plugin:

  • Yes -> If yes, which version?
  • No

Sentry Android Gradle Plugin:

  • Yes -> If yes, which version?
  • No

Proguard/R8:

  • Enabled
  • Disabled

Platform installed with:

  • JCenter
  • Bintray
  • Maven Central
  • Manually

Using this repository so all dependency/build versions are as specified in the sample code available.
Tested using Android Studio 2021.1.1 (not a build related issue, read below for cause)

Problem occurs on all Android versions >= 29

The version of the SDK:
5.1.0-beta6+


I have the following issue:

Setting an activity theme at runtime is broken since 5.1.0-beta6 (problem remains on 5.1.0) ...

Steps to reproduce:

  • Add setTheme(R.style.Theme_AppCompat); before super.onCreate(savedInstanceState); in the sample apps MainActivity.

Expected result:

  • Activity has a black background as per the theme.

Actual result:

  • Activity has a white background (which is from the theme defined in AndroidManifest.xml). Window background from runtime theme change is not being applied.

If I remove usages of ActivityFramesTracker then it behaves as suspected and window background is applied correctly. Can also hardcode isAllActivityCallbacksAvailable to false so the frame tracker applies later, in onCreate, and the issue won't present itself.

My suspicion is that frameMetricsAggregator.add(activity); is being called too early (currently in onActivityPreCreated lifecycle callback), and is causing WindowManager to 'lock in' the window background, preventing it from changing when the theme is updated later on. Notice that other theme attributes (action bar, text color) are applied successfully.

This makes the SDK unusable as the splash screen background is persisting after the activity has finished loading. Not sure why you need to run anything in onActivityPreCreate but if that can be avoided, would be the simplest solution to the problem.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions