tidev / titanium-sdk

🚀 Native iOS and Android Apps with JavaScript
https://titaniumsdk.com/
Other
2.75k stars 1.21k forks source link

Android: overrideUserInterfaceStyle makes issues changing it multiple times #13825

Open m1ga opened 1 year ago

m1ga commented 1 year ago

I have searched and made sure there are no existing issues for the issue I am filing

Description

When running the code below on Android and clicking the button multiple times you can see that around the 4th change it will restart the activity with this method.

After that it can be that is losing the content.

https://user-images.githubusercontent.com/4334997/236195645-78630525-c7b7-4d70-9c4d-10fdc7377e93.mp4

If I remove that recreate part it will keep the content but doesn't update the mode all the time:

https://user-images.githubusercontent.com/4334997/236196307-9d5c432f-2351-49f4-928a-d530b1a4ce7e.mp4

There is a comment in the code

// Note: Works-around a Google bug where it doesn't always call the activity's onNightModeChanged() method.

Which might be referring to this behavior.

Looking at the logs I can see that it is showing

[INFO]  ActivityThread: Schedule relaunch activity: com.miga.testfirebase.TestappActivity
[INFO]  ActivityThread: Schedule relaunch activity: org.appcelerator.titanium.TiActivity

the first time and after a while it is

[INFO]  ActivityThread: Schedule relaunch activity: org.appcelerator.titanium.TiActivity
[INFO]  ActivityThread: Schedule relaunch activity: com.miga.testfirebase.TestappActivity
[INFO]  ActivityThread: Schedule relaunch activity: org.appcelerator.titanium.TiActivity

So the order is different and TiActivity is there twice. So perhaps there is something wrong with the Activity stack that is causing this issue.

Reproducible sample

const win = Titanium.UI.createWindow({backgroundColor: "red"});
const btn = Ti.UI.createButton({title: "change"});
win.add(btn);
var change = false;
btn.addEventListener("click", function() {
    if (change) {
        Ti.UI.overrideUserInterfaceStyle = Ti.UI.USER_INTERFACE_STYLE_LIGHT
    } else {
        Ti.UI.overrideUserInterfaceStyle = Ti.UI.USER_INTERFACE_STYLE_DARK
    }
    change = !change;
})

win.open();

Steps to reproduce

Platform

Android

SDK version you are using

12.2.0

Alloy version you are using

No response

m1ga commented 1 week ago

More test code in https://github.com/tidev/titanium-sdk/issues/13266#issue-1130760215 , the App sample in the initial post. When you change the style multiple times it will show an empty app.