It occurred to me that under some circumstances our app seems to be restarted from scratch after being backgrounded. I managed to track to issue down to MainActivity.OnCreate
being called multiply under the following circumstances
- App is installed from APK and then ran from the installer, after backgrounding the app and starting it from the home screen it's reset to scratch
- This behavior persists until the app is killed and then restarted from the home screen
- App is run from Google Play app, after backgrounding the app and starting it from the home screen it's reset to scratch
- If the app is backgrounded and then started from Play Store it's started correctly
- App is run from home screen, after backgrounding the app and starting it from Google Play it's reset to scratch
When the app is foregrounded from the same launcher it has been started initially, OnCreate
is not called again. There is at least one question reporting a similar behavior, unfortunately there is no answer providing a solution for the behavior.
When MainActivity.OnCreate
is called, the instance of MainActivity
seems to be a different instance than the initial one, since private members that are set in OnCreate
are null
when I'm trying to log them, anyway, the application context does not seem to be recreated from scratch, because AppCenter
seems to be initialized right away on the second run, Xamarin.Forms starts up way quicker and static variables keep their values.
Is there any way to prevent this behavior and just keep a single instance of MainActivity
active?