xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] Requesting Permission causes faulty behavior on SubPages inside Shell on Android #8021

Open SOliasS opened 5 years ago

SOliasS commented 5 years ago

Description

I´m using Plugin.Permissions which uses:

ActivityCompat.RequestPermissions(activity, permissionsToRequest.ToArray(), permissioncode);

To request permissions on Android. When using it on a normal Page:

  1. OnDisappearing will get triggered when the Permission request window/Dialog opens
  2. After the request ist handled and the request window closes OnAppearing get´s triggered

This also works when using the Shell with Tabs.

Bugbehavior

But when you use it within a Tab where you navigated via Push to another page Instead of triggering it on that page it will trigger Only OnAppearing on the selected Tab(Parent) page. This not only completely throws of my Event subscribing/unsubscribing flow, but has potential for bigger displaying issues.

Shell.Current.Navigation.PushAsync(new ModalPage());
Shell.Current.Navigation.PushModalAsync(new ModalPage());//or

Example: When you have a Shell with two tabs(Tab1,Tab2) and you select Tab1 and then from that Page open another page(SubPage1) via Push. On page Tab1 OnDisappearing gets triggered and on SubPage1 OnAppearing gets triggered(normal behavior ends). If you request Permission now, Nothing gets triggered when the Permission request window opens, but when it closes again OnAppearing gets triggered on Page1. If you now init the permission request again OnDisappearing gets triggered on Page1 when the Dialog opens and OnAppearing gets triggered on Page1 when the dialog closes. Also if you now would performShell.Current.Navigation.PopasyncAsync(); OnAppearing would not be triggered on Page1(because it's already displaying).

Expected Behavior

It should trigger OnDisappearing/OnAppearing on the currently displayed page

Reproduction Link

https://github.com/SOliasS/App1--8021.git

kingces95 commented 5 years ago

8021.zip

[0:] Tab1 OnDisappearing
10-16 15:20:33.910 W/ompanyname.app( 7475): Accessing hidden field Landroid/view/View;->mViewFlags:I (light greylist, reflection)
10-16 15:20:33.912 W/ompanyname.app( 7475): Accessing hidden method Landroid/view/View;->setTransitionAlpha(F)V (light greylist, reflection)
10-16 15:20:33.926 W/ompanyname.app( 7475): Accessing hidden method Landroid/view/ViewGroup;->suppressLayout(Z)V (light greylist, reflection)
10-16 15:20:33.934 W/ompanyname.app( 7475): Accessing hidden method Landroid/view/View;->setLeftTopRightBottom(IIII)V (light greylist, reflection)
[0:] Tab2 OnAppearing
[0:] Tab2 OnDisappearing
[0:] Tab1 OnAppearing
[0:] Tab1 OnDisappearing
[0:] SubPage1 OnAppearing
Thread started: <Thread Pool> #2
Thread started: <Thread Pool> #3
Thread started: <Thread Pool> #4
Thread started: <Thread Pool> #5
10-16 15:20:39.216 D/Mono    ( 7475): Loading reference 4 of /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/App1.dll asmctx DEFAULT, looking for Plugin.Permissions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
10-16 15:20:39.216 D/Mono    ( 7475): Assembly Ref addref App1[0xea7c5c80] -> Plugin.Permissions[0xea7c5ce0]: 2
10-16 15:20:39.298 D/Mono    ( 7475): Loading reference 2 of /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Plugin.Permissions.dll asmctx DEFAULT, looking for Plugin.CurrentActivity, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
10-16 15:20:39.299 D/Mono    ( 7475): Assembly Ref addref Plugin.Permissions[0xea7c5ce0] -> Plugin.CurrentActivity[0xea7c5d40]: 3
10-16 15:20:39.301 D/Mono    ( 7475): Loading reference 3 of /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Plugin.Permissions.dll asmctx DEFAULT, looking for Xamarin.Android.Support.Compat, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
10-16 15:20:39.301 D/Mono    ( 7475): Assembly Ref addref Plugin.Permissions[0xea7c5ce0] -> Xamarin.Android.Support.Compat[0xea7c6a00]: 10
10-16 15:20:39.336 D/Mono    ( 7475): Loading reference 4 of /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Plugin.Permissions.dll asmctx DEFAULT, looking for System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
10-16 15:20:39.337 D/Mono    ( 7475): Assembly Ref addref Plugin.Permissions[0xea7c5ce0] -> System.Core[0xe68d0ae0]: 6
10-16 15:20:39.370 D/Mono    ( 7475): DllImport searching in: '__Internal' ('(null)').
10-16 15:20:39.371 D/Mono    ( 7475): Searching for 'java_interop_jnienv_get_object_field'.
10-16 15:20:39.371 D/Mono    ( 7475): Probing 'java_interop_jnienv_get_object_field'.
10-16 15:20:39.371 D/Mono    ( 7475): Found as 'java_interop_jnienv_get_object_field'.
10-16 15:20:42.584 D/Mono    ( 7475): Loading reference 5 of /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/App1.Android.dll asmctx DEFAULT, looking for Plugin.Permissions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
10-16 15:20:42.584 D/Mono    ( 7475): Assembly Ref addref App1.Android[0xe68d1e00] -> Plugin.Permissions[0xea7c5ce0]: 3
10-16 15:20:42.609 D/Mono    ( 7475): Loading reference 5 of /storage/emulated/0/Android/data/com.companyname.app1/files/.__override__/Xamarin.Essentials.dll asmctx DEFAULT, looking for System.Core, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
10-16 15:20:42.609 D/Mono    ( 7475): Assembly Ref addref Xamarin.Essentials[0xe68d03c0] -> System.Core[0xe68d0ae0]: 7
[0:] Tab1 OnAppearing
Thread finished: <Thread Pool> #5
The thread 0x5 has exited with code 0 (0x0).
[0:] SubPage1 OnDisappearing
kingces95 commented 5 years ago

The above log is generated using the zip I attached by clicking on Tab2 then back to Tab1 then Test then Test again, the accepting permissions then Back.

It's unexpected that Tab1 OnAppearing occurs before SubPage1 OnDisappearing. The opposite is expected.

PureWeen commented 4 years ago

Pretty sure this is related https://github.com/xamarin/Xamarin.Forms/issues/7832

SOliasS commented 4 years ago

This also occurs when Closing and reopening the application

SOliasS commented 3 years ago

I found out that this error occures everytime you leave the application and reenter it... for example you jump to antoher application and back into the app only the base gets OnAppearing no sub page gets invoked...