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

Dark Mode toggle - odd behavior #1432

Open
1 of 3 tasks
CallMeAlexO opened this issue Oct 23, 2024 · 1 comment
Open
1 of 3 tasks

Dark Mode toggle - odd behavior #1432

CallMeAlexO opened this issue Oct 23, 2024 · 1 comment
Labels
Bug Something isn't working Core Edge Case This refers to specific setup or rare issue or similar

Comments

@CallMeAlexO
Copy link

CallMeAlexO commented Oct 23, 2024

What happened?

Every night before bed, I plug my phone into the charger. It automatically sets dark mode. It's a feature in vanilla Pixel 8. For some reason, if the active app is Grayjay - the video I'm currently watching stops, and the app shows me a video I watched a few hours ago. I cannot say for sure what makes that video the selected one, but it's usually some video I watched a while ago.

My device is a Pixel 8, running the latest Android 15, but it also happened when I had Android 14.

I'll say that Grayjay isn't the only app with this issue: HomeAssistant restarts on toggle, Brave opens a new tab, YouTube pauses the video. But out of all of these, Grayjay is the most disruptive. Because to back to my video I have to open "history", click my video and then click "skip to XYZ".

Steps to reproduce:

  1. Open Grayjay
  2. From the home tab, select a video.
    3a. Pull up your quick settings, choose dark mode
    3b. Plug your phone into the charger at night with dark mode enabled in preferences
  3. A different video will start playing.

Grayjay Version

264

What plugins are you seeing the problem on?

All

Plugin Version

No response

When do you experience the issue?

  • While logged in
  • While logged out
  • N/A

Relevant log output

Version information (version_name = 264-13-g2bcd59c, version_code = 1, flavor = unstable, build_type = debug)
Device information (brand= google, manufacturer = Google, device = shiba, version-sdk = 35, version-os = )

(e, ExceptionActivity, 2024-10-26 11:28:27): Uncaught exception ("Unknown Context"): Already running.

java.lang.Exception: Already running.
	at com.futo.platformplayer.mdns.ServiceDiscoverer.start(ServiceDiscoverer.kt:40)
	at com.futo.platformplayer.states.StateSync.start(StateSync.kt:72)
	at com.futo.platformplayer.states.StateApp.mainAppStarting(StateApp.kt:416)
	at com.futo.platformplayer.activities.MainActivity.onCreate(MainActivity.kt:253)
	at android.app.Activity.performCreate(Activity.java:9002)
	at android.app.Activity.performCreate(Activity.java:8980)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1526)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4030)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4235)
	at android.app.ActivityThread.handleRelaunchActivityInner(ActivityThread.java:6304)
	at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:6195)
	at android.app.servertransaction.ActivityRelaunchItem.execute(ActivityRelaunchItem.java:79)
	at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:60)
	at android.app.servertransaction.TransactionExecutor.executeNonLifecycleItem(TransactionExecutor.java:174)
	at android.app.servertransaction.TransactionExecutor.executeTransactionItems(TransactionExecutor.java:109)
	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:81)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2636)
	at android.os.Handler.dispatchMessage(Handler.java:107)
	at android.os.Looper.loopOnce(Looper.java:232)
	at android.os.Looper.loop(Looper.java:317)
	at android.app.ActivityThread.main(ActivityThread.java:8705)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:886)
@github-actions github-actions bot added the All label Oct 23, 2024
@CallMeAlexO
Copy link
Author

I found the cause for this, and managed to fix it. Since Futo is not accepting contributions to the core, I'll just outline the problem, and explain how to solve it.

Per the Android docs:

When the app’s theme changes, either through the system setting or AppCompat, it triggers a uiMode configuration change. This means activities are automatically recreated.

This creates an issue for Grayjay, because MainActivity.kt instantiates a lot of things. In this specific case, it tries to create another instance of MainApp, which tries to create another instance of StateSync, which crashes in case of double instantiation.

There are multiple ways to fix this issue. But the easiest by far would be to follow the recommendations given by the Android docs themselves:

An app can handle the implementation of dark theme by declaring that each Activity can handle the uiMode configuration change:

<activity
    android:name=".MyActivity"
    android:configChanges="uiMode" />

When an Activity declares that it handles configuration changes, its onConfigurationChanged() method is called when there is a theme change.

So the solution is straightforward. In AndroidManifest.xml change configChanges to include uiMode.

From this:

            android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout"

To this:

            android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|uiMode"

@support-grayjay support-grayjay added Bug Something isn't working Edge Case This refers to specific setup or rare issue or similar Core and removed All labels Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Core Edge Case This refers to specific setup or rare issue or similar
Projects
None yet
Development

No branches or pull requests

2 participants