xamarin / Essentials

Xamarin.Essentials is no longer supported. Migrate your apps to .NET MAUI, which includes Maui.Essentials.
https://aka.ms/xamarin-upgrade
Other
1.53k stars 505 forks source link

[Bug] Incorrect CurrentActivity value after activities are destroyed and restored by the system #2075

Open sleushunou opened 1 year ago

sleushunou commented 1 year ago

Description

Steps to Reproduce

In our application we have two activities, DialogActivity is opened on top of MainActivity. We use Settings -> Developer Options -> Don't Keep Activities turned ON to simulate system high load. While top activity (DialogActivity) is opened - minimize the app and then open it again.

Expected Behavior

Platform.CurrentActivity should return instance of DialogActivity

Actual Behavior

Platform.CurrentActivity returns instance of MainActivity

Basic Information

Code snippet

Code: link Logs: link Looks like issue happens because paused activity also saved as current activity, which may override already resumed activity.

MainActivity.OnResume()
DialogActivity.OnResume()
MainActivity.OnPause()

void Application.IActivityLifecycleCallbacks.OnActivityPaused(Activity activity) { Activity = activity; Platform.OnActivityStateChanged(activity, ActivityState.Paused); }

Seems like we don't need to update Activity when OnPause called