Essentials icon indicating copy to clipboard operation
Essentials copied to clipboard

[Bug] Launcher: Pixel 4 or newer, Android 12 forces split screen when opening files with default app

Open NavaJoey opened this issue 3 years ago • 4 comments

Description

On Pixel 4 devices or newer with Android 12, if a file is opened using Launcher.OpenAsync() the file is opened in split screen mode adjacent to the source app regardless of whether android:resizeableActivity is false in the manifest file.

The issue is that when it goes into split screen mode the source app is reloaded and any in-progress state is lost in that app.

I've narrowed the problem down to the following logic in the PlatformOpenAsync() method of the Launcher.android.cs file:

#if __ANDROID_24__ if (Platform.HasApiLevelN) flags |= ActivityFlags.LaunchAdjacent; #endif

Removing this logic fixes the issue.

Steps to Reproduce

  1. Deploy your Xamarin App to a Pixel 4 or newer device
  2. Open a PDF or DOCX file from your Xamarin App using Launcher

Expected Behavior

PDF or DOCX file should be opened in a new window and the source app state should remain as before if android:resizeableActivity is false

Actual Behavior

PDF or DOCX file is open adjacent in split screen mode and the source app is reloaded, losing any in-progress state

Basic Information

  • Version with issue:
  • Nuget Packages: Xamarin.Forms 5.0.0.2012, Xamarin.Essentials 1.7.1
  • Affected Devices: Pixel 4a, Pixel 5

NavaJoey avatar Jul 01 '22 02:07 NavaJoey

Also on Pixel 6.

Khadeeja-Madathil avatar Jul 06 '22 13:07 Khadeeja-Madathil

Relates to https://github.com/xamarin/Essentials/issues/1817

joemather avatar Jul 14 '22 15:07 joemather

A side effect of that is that deep linking was working fine but now my app crashes when it is opened. On Android 12, the system tries to go with the adjacent option and since that flag is in the intent, the app is always launched in multi window mode and since my app doesn't support that well, it now crashes. When I use StartActivity, without the Launcher, and I don't use the adjacent flag, it works fine.

ivandamyanov avatar Jul 20 '22 08:07 ivandamyanov

Does anyone have a workaround for this? Or do we build a local version of XE and apply changes @NavaJoey suggested ourselves?

djrpascu avatar Sep 08 '22 07:09 djrpascu

The following worked for me inside the MainApplication

public override void StartActivity(Intent intent)
 {
    // Hack to prevent split screen issues, needs to happen here
    // as disabling in attributes causes app to crash
    if (Build.VERSION.SdkInt >= BuildVersionCodes.N)
    intent.RemoveFlags(ActivityFlags.LaunchAdjacent);

    base.StartActivity(intent);
}

danpowell88 avatar Oct 13 '22 04:10 danpowell88

I don't have a problem launching websites, but this happens when I try to use AppInfo.ShowSettingsUI(); and the above code doesn't help:

image

BillyMartin1964 avatar Nov 15 '22 12:11 BillyMartin1964

I'm seeing this issue occur when simply doing a ComposeEmail() call too.

kkppstudios avatar Nov 15 '22 17:11 kkppstudios

Great that a fix seems on it's way. When can I expect v 1.7.4 (with this fix included?) to be released?

andreasbrostencab avatar Nov 24 '22 14:11 andreasbrostencab

Thanks James and Gerald. You guys are great. Keep up the amazing work!

BillyMartin1964 avatar Dec 01 '22 13:12 BillyMartin1964

Thanks for the fix! Any idea when this will be available? I saw 1.7.4 on the github release page, but it's not yet available on nuget it seems. @jfversluis

rutgersc avatar Dec 08 '22 12:12 rutgersc

Still waiting for 1.7.4 on nuget.. @jfversluis It's there now, thanks! 😁

kkppstudios avatar Dec 11 '22 18:12 kkppstudios

hello friends I found this solution just apply "ResizeableActivity = false," in the MainActivity. https://devblogs.microsoft.com/xamarin/optimizing-android-apps-for-multi-window-mode/

Cr15Denis avatar Feb 05 '23 17:02 Cr15Denis

I am attaching the problem I had on a Samsung galaxy A13 Android 12, And I am attaching the solution in Xamarin Forms Android.

Problem:

https://user-images.githubusercontent.com/70722700/217024937-e1b6e148-e6d0-43a5-a10c-a3bdb9e68901.mp4

Solution:

In the Android project, in the file "MainActivity.cs"

solution

Result:

https://user-images.githubusercontent.com/70722700/217025670-ce964867-f603-4b5d-998c-1065494b27ea.mp4

I hope they can also solve the problem. greetings friends

Cr15Denis avatar Feb 06 '23 16:02 Cr15Denis

Hello friend, right now I published the solution in the github ISSUE, take a look. greetings


De: Samuel @.> Enviado: domingo, 5 de febrero de 2023 20:52 Para: xamarin/Essentials @.> Cc: Cr15Denis @.>; Comment @.> Asunto: Re: [xamarin/Essentials] [Bug] Launcher: Pixel 4 or newer, Android 12 forces split screen when opening files with default app (Issue #2023)

hello friends I found this solution just apply "ResizeableActivity = false," in the MainActivity. https://devblogs.microsoft.com/xamarin/optimizing-android-apps-for-multi-window-mode/

I have this in my app:

Samsung galaxy note 20 - with the samsung app even without having launch LaunchAdjacent (forked copy) and removing the flag on start activity it still opens LaunchAdjacent.

does anyone have a workout around. (is this related to the edge panel in Samsung where you can specify to open in split view)

— Reply to this email directly, view it on GitHubhttps://github.com/xamarin/Essentials/issues/2023#issuecomment-1418261674, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AQ3SJDHTIIEI7LTGSXHRSCDWWAHKTANCNFSM52LGVYWA. You are receiving this because you commented.Message ID: @.***>

Cr15Denis avatar Feb 06 '23 16:02 Cr15Denis

Thank you, all solved.

On Tue, 7 Feb 2023, 3:22 am Cr15Denis, @.***> wrote:

I am attaching the problem I had on a Samsung galaxy A13 Android 12, And I am attaching the solution in Xamarin Forms Android.

Problem:

https://user-images.githubusercontent.com/70722700/217024937-e1b6e148-e6d0-43a5-a10c-a3bdb9e68901.mp4

Solution:

In the Android project, in the file "MainActivity.cs"

[image: solution] https://user-images.githubusercontent.com/70722700/217025138-c40a3109-e7c2-4408-ba58-5da877934642.png

Result:

https://user-images.githubusercontent.com/70722700/217025670-ce964867-f603-4b5d-998c-1065494b27ea.mp4

I hope they can also solve the problem. greetings friends

— Reply to this email directly, view it on GitHub https://github.com/xamarin/Essentials/issues/2023#issuecomment-1419357929, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADGTV2ZJOVCVBZS2BMYXEJTWWEQLZANCNFSM52LGVYWA . You are receiving this because you commented.Message ID: @.***>

samuelGrahame avatar Feb 06 '23 19:02 samuelGrahame