Change platform brigtness is triggered when 'Home' is pressed in iOS 15 Simulator - flutter

I'm having an issue after my Simulator was updated to iOS 15 in my upcoming Flutter app. When I press the 'Home' button at the top it causes my app to fire the didChangePlatformBrightness() function twice.
Seriously thinking on remove this check while the app is already open and leave it only at startup. Anyone with the same problem and any tips on how to solve it?
On Android everything works fine, just as expected.

I solved this question by monitoring the App lifecycle state. If the app is in resumed state, then I change the color scheme, otherwise I'll do nothing. It occurs because when you press the Home button, the app state changes. See the example below:
void didChangePlatformBrightness() {
if (appState == AppLifecycleState.resumed) {
//give the user a choice for restarting the app, so the colors will
//all be set correctly
showThemeChangeWarning();
setColorScheme();
super.didChangePlatformBrightness();
}
}

Related

Flutter: Getting notified of display-mode (Dark/normal) changes in a running app

I use a function that checks MediaQuery.of(context).platformBrightness to determine the platform dark-mode setting:
This is called from the didChangeAppLifecycleState() and during startup - and it mostly works, except that I find that I need to minimise and re-open the app for it to receive the updated display mode.
The MediaQuery platformBrightness value appears to not be updated when the app comes to the foreground, but if you just minimise and bring the app back to forground, it is correct. This is on the Pie emulator using SDK 29.0.2.
Is there a way to directly listen for notifications about platform dark mode?
Note: There are a number of reasons why I don't use the Flutter Theme engine - The app themes are more complex than what Flutter provides and the user is given a preference setting to override the dark mode / normal setting to force the app to go use dark mode or normal mode and even provide dark and normal mode to older versions of android. However when the user selects "Auto" for dark/normal display mode the app should follow the platform mode, and in fact should switch even if th user does not actually leave the app, such as by just pulling down the shade and setting dark mode on or off. For this I would need a way to listen to the events.
UPDATE:
Futher testing shows the the MediaQuery is in fact updated, but that the value is still reflecting the old value when didChangeAppLifecycleState() is called.
For example the following works:
#override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(
if (displayModePreferenceSetting == DISPLAY_MODE_AUTO) {
Timer(Duration(milliseconds: 333), () {
switchDisplayMode(DISPLAY_MODE_AUTO);
});
}
}
It's much simpler than I thought, though I had to find the answer by accident.
A State widget allows you to override a method didChangePlatformBrightness()
Example:
#override
void didChangePlatformBrightness() {
if (MediaQuery.of(context).platformBrightness == Brightness.dark) {
print('PROBED DISPLAY MODE: DARK');
// DO DARK MAGIC HERE
} else {
print('PROBED DISPLAY MODE: NORMAL');
// NORMAL MODE HERE
}
}

Android Application: Returning to the activity where you stopped

I've been making a simple android app here, but i'm stuck with a problem. The app is composed of 1 splash(that is the main activity) and 4 other activities(one of them is used to go to the other 3). Whenever i exit my application and resume it with the process manager, it opens the activity i stopped at. But, when i resume it by clicking on the icon, it goes back to the splash activity. Is there any way to make it always go to where i stopped? Any flag or something i can set on the manifest?
This is an Android bug. The standard behaviour is to return to your application (in the same state as when you left) when launching it from the HOME screen. However, if you started your application for the first time from the installer, this gets broken.
To check if you are seeing this behaviour, go to the Settings->Applications and force close your application. Now go to the HOME screen and start your application. Use your application for a bit. Now press the HOME button to return to the HOME screen and launch your application again by clicking on the icon. It should return to your application exactly the way you left it.
See https://stackoverflow.com/a/16447508/769265 for more information and other links to this long-standing and nasty Android bug.

ios app dosnt work when testing on a test device

When I build the application to the testing phone everything works fine. If i then press the home button go back to the main screen then run the app , again everything works fine.
However if I quit the app to the home screen then close the application from running in the background and then try to run the app again from the main icon, it wont run it just goes to black screen and stops the phone from working or itll load the main view and none of the buttons work.. the only way to fix the phone so its usable again is to lock it and turn the device on again..
has anyone suffered this same issue before?
Sometimes the bootstrap server seems to get confused when you hit the home button and return to the app. If you are testing multi-tasking/background behavior, try the following process:
Build and run from Xcode.
Disconnect your device (your app will quit).
Now, truly quit the app by double tapping the home button and holding down on the app icon.
Finally, reopen the app and test for multi-tasking/backgrounding behavior (your won't get console messages however).

Forcing an iPhone app to quit when Home button is pressed (on iOS4)

I do not want my app to switch to the "task bar" when the Home button is pressed. That's why I would like it to be closed upon Home press. I added this entry to the info.plist file but this does not change the behaviour:
application does not run in background
(and I checked the box...)
I rebuilt the whole app both in debug and release mode but no way. I heard of another key which should be added to the info.plist but I cannot add it through Xcode:
UIApplicationExitsOnSuspend
What is the right way to do that ?
Regards,
Franz
On iOS 4, multitasking is enabled in Xcode projects by default. This prevents the applicationWillTerminate method from being called. If you do not want to support multitasking, place UIApplicationExitsOnSuspend in your MyAppName-Info.plist file and check the checkbox. If you do want to support it, place any code in the applicationDidEnterBackground delegate method that you want to execute before the application enters an inactive state.
What you're doing will indeed stop the application from running in the background, but you can't prevent it from going to the multitasking bar still. Sorry.
You can manually close the application after home button is pressed. When home button is pressed applicationDidEnterBackground is called. In this delegate just write exit(0) and your application will be ended instantly.

multitasking and return to application

on iphone with multitasking and iOS 4.x i run my app it work properly, now if i hit the home button (send a sms) and then double click the home button to return to my app i've notice that the app run like the first time not continue where i left it what is the solution to return to the point where you click the home button.
thanks
You might want to make sure you're implementing the multitasking app delegate callbacks- check out the protocol reference: http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html.