-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Java.Lang.IllegalStateException after MainPage swap #11501
Comments
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
For anyone finding this, I found this issue is also related to dotnet/sdk#28880 and for the code to work in release, you need to add |
Missclick closed, sorry :( |
I have the same issue, when setting a new mainpage when a timer ticks and the user need to re-authenticate. |
Looks very similar to #11259 |
@rkops-bd can you attach a repro? I'm not able to reproduce this with the original posters sample. |
@czmirek I was able to reproduce your issue. From my reproduction, it seems like the issue happens because the MainPage swap is happening while the app is stopped so your workaround is waiting for the app to re-resume. That's something we should fix but I'm just leaving a note here with my observations for other people that come across this. |
Verified this on Visual Studio Enterprise 17.7.0 Preview 1.0. Repro on Android 13.0-API33 with provided Project: |
Anybody who's having trouble with this, here is a workaround, it's not great, but app stopped crashing: public class App : Microsoft.Maui.Controls.Application
{
public static bool IsSleeping { get; set; }
protected override void OnStart()
{
IsSleeping = false;
base.OnStart();
}
protected override void OnSleep()
{
IsSleeping = true;
base.OnSleep();
}
protected override void OnResume()
{
IsSleeping = false;
base.OnResume();
}
public void SetMainPage()
{
MainThread.BeginInvokeOnMainThread(async () =>
{
while (IsSleeping)
{
await Task.Delay(500);
}
Current.MainPage = new MainPage();
});
}
} |
FYI: #19304 I think this issue invokes the same codepaths as whatever is causing this to fail. Once this issue gets addressed, we should reassess the above issue to verify if it's fixed too (My guess is that it should, since I think it's the same underlying cause). If it's not, we should reopen it. |
I found out that the only workaround to temporarily "fix" it now is setting |
Possible related #15788 |
Forwarding a comment PureWeen made in a possibly related issue |
I found the cause in Android. Error Message : "Can not perform this action after onSaveInstanceState"
|
Even if you just minimize the app while it is on splash screen it will crash (just setting the main page inside of App's constructor. Same if you set it inside IWindowCreator). |
This seems to only happen when a debugger is attached? |
No. It crashes on release builds too. and on debug without debugger attached too. It can be fixed by changing |
Description
Exception
Java.Lang.IllegalStateException
is thrown when I try to change theApplication.Current.MainPage
after the browser opened withWebAuthenticator.Default.AuthenticateAsync
is closed without any login.Steps to Reproduce
MainPage.xaml.cs
line 16Link to public reproduction project repository
https://github.com/czmirek/maui_auth_mainpage_fail
Version with bug
7.0 (current)
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 12, API 31, x86_64
Did you find any workaround?
Yes, see this commit in another branch of the repo. I figured out that
MainActivity.OnResume
must run first beforeMainPage
is swapped. It looks like a race condition. The workaround is simple withTaskCompletionSource
but I'm not sure if this is going to work in all cases.Relevant log output
The text was updated successfully, but these errors were encountered: