A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
Hello @Jai Holloway ,
Thanks for your question.
This is most likely the OS silently killing your app to free memory.
I recommend some following workarounds:
- Save and restore state
protected override void OnSleep()
{
Preferences.Set("last_page", "YourPageName");
}
protected override void OnResume()
{
var lastPage = Preferences.Get("last_page", "MainPage");
}
protected override void OnStart()
{
var hadSession = Preferences.Get("last_page", null);
if (hadSession != null)
{
// restore session
}
}
- If your app uses authentication, please refresh token on resume.
protected override async void OnResume()
{
var tokenExpiry = Preferences.Get("token_expiry", DateTime.MinValue.ToString());
var expiry = DateTime.Parse(tokenExpiry);
if (DateTime.UtcNow >= expiry)
{
await RefreshTokenAsync();
}
}
- Simulator is not reliable for inactivity testing. It's better to test on a real device.
4.If your app needs to stay alive in the background (iOS only), declare background modes in Info.plist.
<key>UIBackgroundModes</key>
<array>
<string>fetch</string>
<string>remote-notification</string>
</array>
I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.