Closed uzairali001 closed 4 years ago
Please attach a zipped reproduction.
I am getting the same condition. This started to happen after upgrading to the latest stable xamarin.forms version. Do not yet have a reproducible sample.
However, the pattern is the same: after OnResume(). Here is a small stacktrace:
NavigationModel.Push (Xamarin.Forms.Page page, Xamarin.Forms.Page ancestralNav)
Platform.SetPageInternal (Xamarin.Forms.Page newRoot)
Platform.SetPage (Xamarin.Forms.Page newRoot)
FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page)
FormsAppCompatActivity.SetMainPage ()
FormsAppCompatActivity.OnResume ()
MainActivity.OnResume ()
Activity.n_OnResume (System.IntPtr jnienv, System.IntPtr native__this)
I can't provide repo because this problem can occurred in newly created project and since it is random I can't even provide to take any steps to reproduce it but I will provide output log whenever I get this error again
Here's the stack trace
**Xamarin.Forms.InvalidNavigationException:** 'Ancestor must be provided for all pushes except first'
04-07 13:46:45.378 D/Mono (20020): DllImport attempting to load: '/system/lib64/liblog.so'.
04-07 13:46:45.379 D/Mono (20020): DllImport loaded library '/system/lib64/liblog.so'.
04-07 13:46:45.379 D/Mono (20020): DllImport searching in: '/system/lib64/liblog.so' ('/system/lib64/liblog.so').
04-07 13:46:45.379 D/Mono (20020): Searching for '__android_log_print'.
04-07 13:46:45.379 D/Mono (20020): Probing '__android_log_print'.
04-07 13:46:45.380 D/Mono (20020): Found as '__android_log_print'.
04-07 13:46:45.389 I/MonoDroid(20020): UNHANDLED EXCEPTION:
04-07 13:46:45.394 I/MonoDroid(20020): Xamarin.Forms.InvalidNavigationException: Ancestor must be provided for all pushes except first
04-07 13:46:45.395 I/MonoDroid(20020): at Xamarin.Forms.Internals.NavigationModel.Push (Xamarin.Forms.Page page, Xamarin.Forms.Page ancestralNav) [0x00010] in D:\a\1\s\Xamarin.Forms.Core\NavigationModel.cs:134
04-07 13:46:45.395 I/MonoDroid(20020): at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPageInternal (Xamarin.Forms.Page newRoot) [0x00046] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:333
04-07 13:46:45.395 I/MonoDroid(20020): at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x000d6] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:285
04-07 13:46:45.395 I/MonoDroid(20020): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x0001a] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:507
04-07 13:46:45.395 I/MonoDroid(20020): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:541
04-07 13:46:45.395 I/MonoDroid(20020): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnResume () [0x00064] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:401
04-07 13:46:45.395 I/MonoDroid(20020): at Android.App.Activity.n_OnResume (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <d3b924763d4a465c85b26f6e8edc8a53>:0
04-07 13:46:45.395 I/MonoDroid(20020): at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.14(intptr,intptr)
04-07 13:46:45.408 E/AppCenterCrashes(20020): Unhandled Exception from source=AndroidEnvironment
04-07 13:46:45.408 E/AppCenterCrashes(20020): Xamarin.Forms.InvalidNavigationException: Ancestor must be provided for all pushes except first
04-07 13:46:45.408 E/AppCenterCrashes(20020): at Xamarin.Forms.Internals.NavigationModel.Push (Xamarin.Forms.Page page, Xamarin.Forms.Page ancestralNav) [0x00010] in D:\a\1\s\Xamarin.Forms.Core\NavigationModel.cs:134
04-07 13:46:45.408 E/AppCenterCrashes(20020): at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPageInternal (Xamarin.Forms.Page newRoot) [0x00046] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:333
04-07 13:46:45.408 E/AppCenterCrashes(20020): at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x000d6] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:285
04-07 13:46:45.408 E/AppCenterCrashes(20020): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x0001a] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:507
04-07 13:46:45.408 E/AppCenterCrashes(20020): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:541
04-07 13:46:45.408 E/AppCenterCrashes(20020): at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnResume () [0x00064] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:401
04-07 13:46:45.408 E/AppCenterCrashes(20020): at Android.App.Activity.n_OnResume (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in <d3b924763d4a465c85b26f6e8edc8a53>:0
04-07 13:46:45.408 E/AppCenterCrashes(20020): at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.14(intptr,intptr)
04-07 13:46:45.421 D/Mono (20020): Requesting loading reference 5 (of 6) of /storage/emulated/0/Android/data/com.ikonbusiness.ikonapp/files/.__override__/Microsoft.AppCenter.Crashes.dll
04-07 13:46:45.421 D/Mono (20020): Loading reference 5 of /storage/emulated/0/Android/data/com.ikonbusiness.ikonapp/files/.__override__/Microsoft.AppCenter.Crashes.dll asmctx DEFAULT, looking for System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
04-07 13:46:45.422 D/Mono (20020): Assembly Ref addref Microsoft.AppCenter.Crashes[0x7c8d51bb00] -> System.Core[0x7c380cc100]: 8
04-07 13:46:45.465 D/Mono (20020): DllImport searching in: '__Internal' ('(null)').
04-07 13:46:45.465 D/Mono (20020): Searching for 'java_interop_jnienv_new_local_ref'.
04-07 13:46:45.465 D/Mono (20020): Probing 'java_interop_jnienv_new_local_ref'.
04-07 13:46:45.465 D/Mono (20020): Found as 'java_interop_jnienv_new_local_ref'.
04-07 13:46:45.542 W/usiness.ikonap(20020): JNI RegisterNativeMethods: attempt to register 0 native methods for android.runtime.JavaProxyThrowable
04-07 13:46:45.544 D/Mono (20020): DllImport searching in: '__Internal' ('(null)').
04-07 13:46:45.545 D/Mono (20020): Searching for 'java_interop_jnienv_throw'.
04-07 13:46:45.545 D/Mono (20020): Probing 'java_interop_jnienv_throw'.
04-07 13:46:45.545 D/Mono (20020): Found as 'java_interop_jnienv_throw'.
**Xamarin.Forms.InvalidNavigationException:** 'Ancestor must be provided for all pushes except first'
04-07 13:46:46.355 E/mono-rt (20020): [ERROR] FATAL UNHANDLED EXCEPTION: Xamarin.Forms.InvalidNavigationException: Ancestor must be provided for all pushes except first
04-07 13:46:46.355 E/mono-rt (20020): at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.14(intptr,intptr)
04-07 13:46:46.355 E/mono-rt (20020): at (wrapper native-to-managed) Android.Runtime.DynamicMethodNameCounter.14(intptr,intptr)
I can confirm it only happens in v4.5. In v4.4 of Xamarin.Forms everything was working fine. Digging through the commits
I'm guessing it's related with this commit https://github.com/xamarin/Xamarin.Forms/commit/d9f580e529db147a77165040dc3c1964f597129a by @paymicro and @rmarinho
I'm getting this error every time when trying to navigate to a view after successful fingerprint authentication. It was working earlier before updating to XF 4.6 I'm using https://github.com/smstuebe/xamarin-fingerprint plugin. @smstuebe
@uzairali001, @bcaceiro I would like to investigate more about this issue, do you have any reproduction sample?.
I don't have a small reproduction sample. And my application is way too big and complex to remove private stuff :/
The thing that I suspect is regarding onResume in Android.
I can confirm it only happens in v4.5. In v4.4 of Xamarin.Forms everything was working fine. Digging through the commits
I'm guessing it's related with this commit d9f580e by @paymicro and @rmarinho
@bcaceiro Does downgrading just the android XF version solve this temporarily?
Well I've downgraded the Xamarin.Forms version for both android and ios
Any update on this issue?
Google Prelaunch Report says the app is crashing on certain devices with the same error message.
I am using XForms 4.5.0.396
android.runtime.JavaProxyThrowable: at Xamarin.Forms.Internals.NavigationModel.Push (Xamarin.Forms.Page page, Xamarin.Forms.Page ancestralNav) [0x0001a] in <3015a2ac424d4bfc9c78e6a5d3a3fc66>:0
at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPageInternal (Xamarin.Forms.Page newRoot) [0x00046] in <805334c64ae441c38c4c6d2276e9f047>:0
at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x000d6] in <805334c64ae441c38c4c6d2276e9f047>:0
at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x00020] in <805334c64ae441c38c4c6d2276e9f047>:0
at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x0000c] in <805334c64ae441c38c4c6d2276e9f047>:0
at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnResume () [0x00064] in <805334c64ae441c38c4c6d2276e9f047>:0
at Android.App.Activity.n_OnResume (System.IntPtr jnienv, System.IntPtr native__this) [0x00009] in
Same here. App is randomly crashing after being in sleep for a while. Attached the full generated report from production device.
Report Android: 8.1.0 Android Build: 01-11-09.00-OG-U00-H01 Manufacturer: Zebra Technologies Model: TC20 Start Date: 2020-05-28T13:25:17.215Z Date: 2020-05-28T14:54:26.212Z
Xamarin Exception Stack:
Xamarin.Forms.InvalidNavigationException: Ancestor must be provided for all pushes except first
at Xamarin.Forms.Internals.NavigationModel.Push (Xamarin.Forms.Page page, Xamarin.Forms.Page ancestralNav) [0x0001a] in
Thread 2: 0 dalvik.system.VMStack.getThreadStackTrace(VMStack.java:-2) 1 java.lang.Thread.getStackTrace(Thread.java:1538) 2 java.lang.Thread.getAllStackTraces(Thread.java:1588) 3 com.microsoft.appcenter.crashes.Crashes.saveUncaughtException(Crashes.java:1137) 4 com.microsoft.appcenter.crashes.WrapperSdkExceptionManager.saveWrapperException(WrapperSdkExceptionManager.java:58) 5 crc647ee522241a81e859.MainActivity.n_onResume(MainActivity.java:-2) 6 crc647ee522241a81e859.MainActivity.onResume(MainActivity.java:58) 7 android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1356) 8 android.app.Activity.performResume(Activity.java:7131) 9 android.app.ActivityThread.performResumeActivity(ActivityThread.java:3559) 10 android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3624) 11 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1641) 12 android.os.Handler.dispatchMessage(Handler.java:106) 13 android.os.Looper.loop(Looper.java:164) 14 android.app.ActivityThread.main(ActivityThread.java:6518) 15 java.lang.reflect.Method.invoke(Method.java:-2) 16 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 17 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Thread 571: 0 java.lang.Object.wait(Object.java:-2) 1 java.lang.Daemons$ReferenceQueueDaemon.runInternal(Daemons.java:178) 2 java.lang.Daemons$Daemon.run(Daemons.java:103) 3 java.lang.Thread.run(Thread.java:764)
Thread 572: 0 java.lang.Object.wait(Object.java:-2) 1 java.lang.Object.wait(Object.java:422) 2 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:188) 3 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:209) 4 java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:232) 5 java.lang.Daemons$Daemon.run(Daemons.java:103) 6 java.lang.Thread.run(Thread.java:764)
Thread 573: 0 java.lang.Object.wait(Object.java:-2) 1 java.lang.Daemons$FinalizerWatchdogDaemon.sleepUntilNeeded(Daemons.java:297) 2 java.lang.Daemons$FinalizerWatchdogDaemon.runInternal(Daemons.java:277) 3 java.lang.Daemons$Daemon.run(Daemons.java:103) 4 java.lang.Thread.run(Thread.java:764)
Thread 585: 0 android.os.MessageQueue.nativePollOnce(MessageQueue.java:-2) 1 android.os.MessageQueue.next(MessageQueue.java:325) 2 android.os.Looper.loop(Looper.java:142) 3 android.os.HandlerThread.run(HandlerThread.java:65)
Thread 592: 0 android.os.MessageQueue.nativePollOnce(MessageQueue.java:-2) 1 android.os.MessageQueue.next(MessageQueue.java:325) 2 android.os.Looper.loop(Looper.java:142) 3 android.os.HandlerThread.run(HandlerThread.java:65)
Thread 594: 0 android.os.MessageQueue.nativePollOnce(MessageQueue.java:-2) 1 android.os.MessageQueue.next(MessageQueue.java:325) 2 android.os.Looper.loop(Looper.java:142) 3 android.os.HandlerThread.run(HandlerThread.java:65)
Thread 606: 0 android.net.LocalSocketImpl.readba_native(LocalSocketImpl.java:-2) 1 android.net.LocalSocketImpl.-wrap1 2 android.net.LocalSocketImpl$SocketInputStream.read(LocalSocketImpl.java:110) 3 com.qti.tcmclient.DpmTcmClient$TcmReceiver.run(DpmTcmClient.java:143) 4 java.lang.Thread.run(Thread.java:764)
Thread 609: 0 java.lang.Object.wait(Object.java:-2) 1 com.android.okhttp.okio.AsyncTimeout.awaitTimeout(AsyncTimeout.java:311) 2 com.android.okhttp.okio.AsyncTimeout.-wrap0 3 com.android.okhttp.okio.AsyncTimeout$Watchdog.run(AsyncTimeout.java:286)
Thread 857: 0 java.lang.Object.wait(Object.java:-2) 1 java.lang.Object.wait(Object.java:422) 2 com.google.android.gms.measurement.internal.zzbv.run
I'm encountering this, too - same version and stack trace - except unlike OP, I haven't seen it in development, only in production. :-(
I encountered it in development as well. The most obvious way for me to reproduce it in most times is the app needs to be in sleep for a while(>1 hr).
Report
Android: 8.1.0 Android Build: 01-11-09.00-OG-U00-H01 Manufacturer: Zebra Technologies Model: TC20 Start Date: 2020-05-27T14:40:26.32Z Date: 2020-05-27T16:36:17.493Z
Xamarin Exception Stack: Xamarin.Forms.InvalidNavigationException: Ancestor must be provided for all pushes except first at Xamarin.Forms.Internals.NavigationModel.Push (Xamarin.Forms.Page page, Xamarin.Forms.Page ancestralNav) [0x00010] in D:\a\1\s\Xamarin.Forms.Core\NavigationModel.cs:134 at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPageInternal (Xamarin.Forms.Page newRoot) [0x00046] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:334 at Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage (Xamarin.Forms.Page newRoot) [0x000d6] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\Platform.cs:286 at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage (Xamarin.Forms.Page page) [0x0001a] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:510 at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:543 at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnResume () [0x00064] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:404 at AppName.Droid.MainActivity.OnResume () [0x00001] in C:\Users\user\source\dir1\AppName\AppName\AppName.Android\Activities\MainActivity.cs:105 at Android.App.Activity.n_OnResume (System.IntPtr jnienv, System.IntPtr native__this) [0x00008] in <94c63bf70a6244b090f8036e8ac91ed5>:0 at (wrapper dynamic-method) Android.Runtime.DynamicMethodNameCounter.22(intptr,intptr)
Thread 2: 0 dalvik.system.VMStack.getThreadStackTrace(VMStack.java:-2) 1 java.lang.Thread.getStackTrace(Thread.java:1538) 2 java.lang.Thread.getAllStackTraces(Thread.java:1588) 3 com.microsoft.appcenter.crashes.Crashes.saveUncaughtException(Crashes.java:1137) 4 com.microsoft.appcenter.crashes.WrapperSdkExceptionManager.saveWrapperException(WrapperSdkExceptionManager.java:58) 5 crc647ee522241a81e859.MainActivity.n_onResume(MainActivity.java:-2) 6 crc647ee522241a81e859.MainActivity.onResume(MainActivity.java:58) 7 android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1356) 8 android.app.Activity.performResume(Activity.java:7131) 9 android.app.ActivityThread.performResumeActivity(ActivityThread.java:3559) 10 android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3624) 11 android.app.ActivityThread$H.handleMessage(ActivityThread.java:1641) 12 android.os.Handler.dispatchMessage(Handler.java:106) 13 android.os.Looper.loop(Looper.java:164) 14 android.app.ActivityThread.main(ActivityThread.java:6518) 15 java.lang.reflect.Method.invoke(Method.java:-2) 16 com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 17 com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Thread 583: 0 java.lang.Object.wait(Object.java:-2) 1 java.lang.Daemons$ReferenceQueueDaemon.runInternal(Daemons.java:178) 2 java.lang.Daemons$Daemon.run(Daemons.java:103) 3 java.lang.Thread.run(Thread.java:764)
Thread 584: 0 java.lang.Object.wait(Object.java:-2) 1 java.lang.Object.wait(Object.java:422) 2 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:188) 3 java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:209) 4 java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:232) 5 java.lang.Daemons$Daemon.run(Daemons.java:103) 6 java.lang.Thread.run(Thread.java:764)
Thread 585: 0 java.lang.Object.wait(Object.java:-2) 1 java.lang.Daemons$FinalizerWatchdogDaemon.sleepUntilNeeded(Daemons.java:297) 2 java.lang.Daemons$FinalizerWatchdogDaemon.runInternal(Daemons.java:277) 3 java.lang.Daemons$Daemon.run(Daemons.java:103) 4 java.lang.Thread.run(Thread.java:764)
Thread 602: 0 android.os.MessageQueue.nativePollOnce(MessageQueue.java:-2) 1 android.os.MessageQueue.next(MessageQueue.java:325) 2 android.os.Looper.loop(Looper.java:142) 3 android.os.HandlerThread.run(HandlerThread.java:65)
Thread 610: 0 android.os.MessageQueue.nativePollOnce(MessageQueue.java:-2) 1 android.os.MessageQueue.next(MessageQueue.java:325) 2 android.os.Looper.loop(Looper.java:142) 3 android.os.HandlerThread.run(HandlerThread.java:65)
Thread 612: 0 android.os.MessageQueue.nativePollOnce(MessageQueue.java:-2) 1 android.os.MessageQueue.next(MessageQueue.java:325) 2 android.os.Looper.loop(Looper.java:142) 3 android.os.HandlerThread.run(HandlerThread.java:65)
Thread 621: 0 android.net.LocalSocketImpl.readba_native(LocalSocketImpl.java:-2) 1 android.net.LocalSocketImpl.-wrap1 2 android.net.LocalSocketImpl$SocketInputStream.read(LocalSocketImpl.java:110) 3 com.qti.tcmclient.DpmTcmClient$TcmReceiver.run(DpmTcmClient.java:143) 4 java.lang.Thread.run(Thread.java:764)
Thread 623: 0 java.lang.Object.wait(Object.java:-2) 1 com.android.okhttp.okio.AsyncTimeout.awaitTimeout(AsyncTimeout.java:311) 2 com.android.okhttp.okio.AsyncTimeout.-wrap0 3 com.android.okhttp.okio.AsyncTimeout$Watchdog.run(AsyncTimeout.java:286)
Thread 670: 0 java.lang.Object.wait(Object.java:-2) 1 java.lang.Object.wait(Object.java:422) 2 com.google.android.gms.measurement.internal.zzbv.run
Can someone who is seeing this issue post there Android file that's inheriting from FormsAppCompatActivity
From the stack traces it seems like the code is reusing a navpage that's already part of a different hierarchy and then setting a new mainpage
The normal app flow onresume (like from a template) won't hit this stack trace
D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:510
at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage () [0x00000] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:543
at Xamarin.Forms.Platform.Android.FormsAppCompatActivity.OnResume () [0x00064] in D:\a\1\s\Xamarin.Forms.Platform.Android\AppCompat\FormsAppCompatActivity.cs:404
Because SetMainPage is only called from OnResume if the mainpage is changed
if (_needMainPageAssign)
{
_needMainPageAssign = false;
SetMainPage();
}
I tried a few variations of setting the main page but all the variations I tried didn't trigger this issue.
AFAICT there's something specific to how you are resetting the mainpage on resume that's triggering this
@PureWeen in my case,
protected override void OnResume()
{
base.OnResume();
UpdateUI();
}
protected void UpdateUI()
{
var decorView = Window.DecorView;
int uiOptions = (int)decorView.SystemUiVisibility;
uiOptions |= (int)SystemUiFlags.LowProfile;
uiOptions |= (int)SystemUiFlags.Fullscreen;
uiOptions |= (int)SystemUiFlags.HideNavigation;
uiOptions |= (int)SystemUiFlags.ImmersiveSticky;
decorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;
decorView.SetOnSystemUiVisibilityChangeListener(new CustomDecorView(decorView));
}
This is the only method called in OnResume from the AppCompat. To hide the status and navigationbar (fullscreen application).
Another thing, in my specific project, I change the MainPage quite sometimes. Relevant is that in forms v4.4, everything is working as expected. I cannot make a reproducible sample since the application is yet quite complex. So, my suggestion, as before, would be to see if the changes from v4.4 to v4.5 are crucial, regarding navigation.
I can reliably get this error thrown every time (it's not random for me).
I'm using the Xamarin.Essentials WebAuthenicator.
I add a new activity to MainActivity.cs
[Activity(NoHistory = true, LaunchMode = LaunchMode.SingleTop)]
[IntentFilter(new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = "mycustomurl")]
public class WebAuthenticationCallbackActivity : Xamarin.Essentials.WebAuthenticatorCallbackActivity
{
}
From App.cs I call
MainPage = new Home();
To show the Home page - fine.
On the Home page, I call:
WebAuthenticatorResult authResult = await WebAuthenticator.AuthenticateAsync(loginUrl, returnUrl);
This launches the login Api in Custom Tabs - and then returns to the app - all fine.
If at anypoint, having returned to the app, I call:
App.Current.MainPage = new NewPage();
The Ancestor must be provided for all pushes except first
exception is thrown.
Note this happens on Forms 4.5 and up. I have no issues on Forms 4.4.0.991864
In our Xam Forms Android app we can trigger this issue by holding down the task button (Android 7.1.1 Emulator, right hand device button) to initiate the multi task feature. Clicking the app to resume it crashes it every time. Stack trace from app center is the same/very similar to those posted before. Interestingly, as soon as multi mode enables and offers the list of other apps to run simultaneously our app view switches to our Android splashscreen.
Further testing shows that once multi task is enabled a call is made to OnCreate in the Android MainActivity.cs which causes a new App object be created. When that runs our Android splash appears again - presume at this point the Forms navigation is destroyed hence the crash?
My money is on this change breaking it
https://github.com/xamarin/Xamarin.Forms/pull/8790/files#diff-c986fa1fa0e47f337a0dcc0ec16b5d05R314
https://github.com/xamarin/Xamarin.Forms/pull/8790/files#diff-9417b87fd39d525a77c409b8b304a37cR415
Still not sure the path that causes the exception
@Lydecker is there anyway you can send me your app?
shneuvil at microsoft dot com
@shawsky can you send me your app? or post your MainActivity.cs here?
@shawsky can you send me your app? or post your MainActivity.cs here?
I can't send the app, sorry, I'm trying to get a repro together for you though. MainActivity.cs below. We're migrated to AndroidX, supporting API 21-29. We use Fresh for Mvvm and navigation.
I've removed the Android splashscreen and the issue persists, we have Xam Forms splash doing start up stuff and this displays when I start multi app mode on the emulator before the crash.
[Activity(Label = "xxxx.zzzz", Icon = "@drawable/icon", Theme = "@style/MainTheme", MainLauncher = true,
ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation, ScreenOrientation = ScreenOrientation.Portrait, LaunchMode = LaunchMode.SingleTask)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Rg.Plugins.Popup.Popup.Init(this, savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState);
ZXing.Net.Mobile.Forms.Android.Platform.Init();
global::Xamarin.Forms.Forms.Init(this, savedInstanceState);
LoadApplication(new App());
App.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
}
}
@shawsky
Clicking the app to resume it crashes it every time.
Is this from the initial load of the app? Do you navigate anywhere and then go into multi task?
What's the composition of your MainPage? Is it a navigationPage? shell? other? Do you swap out the main page during initial load? Do you push any pages onto the stack during initial load?
@PureWeen
Is this from the initial load of the app? Do you navigate anywhere and then go into multi task?
What's the composition of your MainPage? Is it a navigationPage? shell? other? Do you swap out >the main page during initial load? Do you push any pages onto the stack during initial load?
I've just pared our app back to something I can give you and it doesn't crash :(
To answer your questions:
Once you enable multi app use, the split screen appears on the emulator and immediately our app changes to our splash page (forms not Android, see below) as the png appears. Nothing happens until you interact with the app, so from the emulator a click on it will cause the crash. It will also crash when sleeping the app but it doesn't happen consistently, the multi app approach does it every single time.
We have the following in app.xaml.cs:
protected override void OnStart()
{
MainPage = new FreshNavigationContainer(FreshPageModelResolver.ResolvePageModel<SplashPageModel>());
}
We don't use shell at all. No pages pushed to the stack, main page is swapped as necessary:
The splash page determines if the app config has been completed. If not main page is set to a config page with no navigation stack (so yes the main page can change as the app starts up).
Otherwise the splashpagemodel pushes to the login which then sets up a Fresh navigator (FreshTabbedFONavigationContainer) - a master detail page that give us a burger menu/tabbed page as the master. This is the main app and the active navigation stack at the point of triggering the issue.
Is there anything I can do locally to provide you better info?
The splash page determines if the app config has been completed. If not main page is set to a config page with no navigation stack (so yes the main page can change as the app starts up).
Where does this logic live inside the SplashPage? Is it fired from OnAppearing? Is it async?
YEEEEEEEEEEEESSSSSSSSSSSSSS!!!!!!!!!!!!!!!!!!!!!!!!!
Thank you @shawsky
So the basic issue here is that swapping your main page while the app is paused broke.
The simplest way to reproduce is this
protected override async void OnStart()
{
var contentPage = new ContentPage();
base.OnStart();
MainPage = contentPage;
await Task.Delay(5000);
// Background the app here
MainPage = new NavigationPage(new MainPage());
}
I have a PR for this that I will attach a nuget for here so you can all test.
As a workaround you could probably override OnSleep in your app file to keep track if the app has backgrounded
protected override void OnSleep()
{
base.OnSleep();
}
If it is, than don't replace the MainPage. Wait for the app to be resumed again before swapping it.
Here's a nuget if anyone wants to test
YEEEEEEEEEEEESSSSSSSSSSSSSS!!!!!!!!!!!!!!!!!!!!!!!!!
Thank you @shawsky
Nice! Excellent progress whilst the UK was asleep.
I've tested the nuget and it's fixed., thanks! When turning on multi app mode the splashscreen appears as before but interacting with the app brings it back to life.
I could take a look at our startup process as we potentially swap the main page in OnStart but we don't in OnSleep or OnResume. Any mileage in this or is it ok given the fix?
Looking at the life cycle methods when triggering the bug:
OnSleep is called and OnStart is called immediately after (where we do set MainPage) - this should be calling OnResume as the app doesn't terminate. shouldn't it?
I can't mitigate with a sleep flag as the app gets new'd up when the bug occurs and therefore the flag is reset.
No biggie, given there's a fix in the pipeline.
@Lydecker is there anyway you can send me your app?
shneuvil at microsoft dot com
Hi,
Do you still want a copy of my project?
@Lydecker It's fine
But if you and others can test the nuget here that would be super helpful https://github.com/xamarin/Xamarin.Forms/issues/10182#issuecomment-645736879
@samhouts @PureWeen what version would this be released in & when as i see its been merged with 4.6.0 but there's already 4.7.0 nuget avaialable?
the next SR's of 4.6 and 4.7 should have this fix
I still got this issue with Xamarin Forms version 5.0.0.2012 and it's happening randomly:
Xamarin.Forms.Internals.NavigationModel.Push(Xamarin.Forms.Page page, Xamarin.Forms.Page ancestralNav) in <978ec34c5c9c4c4eb3d73b6da958bcd6> Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPageInternal(Xamarin.Forms.Page newRoot) in <04c545f414d24a37af95d995791bb9a9> Xamarin.Forms.Platform.Android.AppCompat.Platform.SetPage(Xamarin.Forms.Page newRoot) in <04c545f414d24a37af95d995791bb9a9> Xamarin.Forms.Platform.Android.FormsAppCompatActivity.InternalSetPage(Xamarin.Forms.Page page) in <04c545f414d24a37af95d995791bb9a9> Xamarin.Forms.Platform.Android.FormsAppCompatActivity.SetMainPage() in <04c545f414d24a37af95d995791bb9a9> Xamarin.Forms.Platform.Android.FormsAppCompatActivity.AppOnPropertyChanged(System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) in <04c545f414d24a37af95d995791bb9a9> Xamarin.Forms.BindableObject.OnPropertyChanged(System.String propertyName) in <978ec34c5c9c4c4eb3d73b6da958bcd6> Xamarin.Forms.Element.OnPropertyChanged(System.String propertyName) in <978ec34c5c9c4c4eb3d73b6da958bcd6> Xamarin.Forms.Application.set_MainPage(Xamarin.Forms.Page value) in <978ec34c5c9c4c4eb3d73b6da958bcd6>
Codes:
await MainThread.InvokeOnMainThreadAsync(() =>
{
try
{
Application.Current.MainPage = MainTabNavigationContainer.CreateNew();
}
catch (Exception ex)
{
RaygunClient.Current.Send(ex);
}
});
Thanks, Kenny.
Yes, I had it today too. Xamarin Forms version 5.0.0.2012
Description
Sometimes I get this exception during development but I still haven't got it once during production, should I ignore this safely?
Edit: This bug is causing crash in production app as well. It has something to do with OnResume usually app crashes when it's minimized then restore from recent apps
Steps to Reproduce
Expected Behavior
This exception shouldn't raise
Actual Behavior
Exception thrown causing application crash