Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ActivityFrameTracker breaks runtime theme changing. #1659

Closed
7 of 27 tasks
kaneoriley opened this issue Aug 19, 2021 · 5 comments · Fixed by #1661
Closed
7 of 27 tasks

ActivityFrameTracker breaks runtime theme changing. #1659

kaneoriley opened this issue Aug 19, 2021 · 5 comments · Fixed by #1661
Labels
Platform: Android Type: Bug Something isn't working

Comments

@kaneoriley
Copy link

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.

@marandaneto
Copy link
Contributor

@lennykano thanks for reporting, interesting corner case, let me investigate this, if its the case, we can move the calls from onActivityPreCreated to onActivityCreated

@kaneoriley
Copy link
Author

@marandaneto thanks for the quick turnaround.

tirkarthi added a commit to tirkarthi/NotificationDictionary that referenced this issue Sep 12, 2021
Add error message for database crash and enable Sentry.
Pin sentry 4.3.0 due to getsentry/sentry-java#1659 being not resolved.
@VGJohn
Copy link

VGJohn commented Oct 18, 2021

This still seems to be an issue, on Sentry 5.0.1 calling setTheme on the activity works correctly but doesn't when using Sentry 5.2.3.

I've attached a sample project showing the issue, the windowBackground of the activity is set to red as defined in theme but Sentry 5.2.3 prevents the theme from being applied. If you uncomment the gradle configuration to switch back to Sentry 5.0.1 then the red activity windowBackground is applied correctly as expected.

SentryIssueDemo.zip

@marandaneto
Copy link
Contributor

@VGJohn probably because of #1768 so a fix is on its way, thanks for reporting.

@VGJohn
Copy link

VGJohn commented Oct 18, 2021

Just to confirm, Sentry 5.2.4 fixed my issue, thanks! 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Android Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants