Repository navigation
Description
Current behavior 🐛
On Skia Android, if a custom-scheme deep link (protocol activation) is delivered to an app that is already running, the app renders a black screen from then on. Cold start renders fine.
The app is otherwise healthy: process alive, XAML tree built, activation delivered and handled, no exception logged.
Root cause: ApplicationActivity and every app head derived from it declare no LaunchMode, so Android uses the default standard mode and creates a new activity instance for every incoming intent. The deep link stacks a second MainActivity on top of the first one (adb shell dumpsys activity activities):
Hist #1: ActivityRecord{a002414} <- new instance from the protocol intent (resumed, focused)
Hist #0: ActivityRecord{b28bdf} <- original instance (paused)
Uno's single XAML window stays bound to the first instance, so the second instance presents nothing. Its SurfaceView never receives its relative z-order (no relativeParentId in dumpsys SurfaceFlinger --list, whereas a healthy window has relativeParentId=... z=-2).
Observed on an Android 35 (Pixel 7) emulator with the SamplesApp Android head, same build/device in all rows:
| Case | Screencap size | Activity instances |
|---|---|---|
| Cold launch | ~179 KB (renders) | 1 |
| Protocol intent, default flags | ~15 KB (all black) | 2, stacked |
Protocol intent + FLAG_ACTIVITY_SINGLE_TOP (-f 0x20000000) |
~179 KB (renders) | 1 |
Expected behavior 🎯
A deep link to a running app should bring the existing window to the front and raise the protocol activation on it, without creating a second activity. ApplicationActivity.OnNewIntent already forwards the intent to NativeApplication.TryHandleIntent (its comment even mentions SingleTask), but it can only be reached if the app uses a launch mode that reuses the instance.
How to reproduce it (as minimally and precisely as possible) 🔬
- Create an Uno app with Skia Android (
dotnet new unoapp), or use the SamplesApp Android head. - Register a protocol on
MainActivityexactly as in the protocol activation docs, and do not setLaunchMode:
[Activity(Exported = true, MainLauncher = true /* ... */)]
[IntentFilter(
new[] { Android.Content.Intent.ActionView },
Categories = new[] { Android.Content.Intent.CategoryDefault, Android.Content.Intent.CategoryBrowsable },
DataScheme = "myscheme")]
public class MainActivity : Microsoft.UI.Xaml.ApplicationActivity
{
}- Launch the app and confirm it renders:
adb shell am start -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n <package>/<activity> - While it is running, deliver a deep link:
adb shell am start -a android.intent.action.VIEW -d "myscheme://x" - The screen is black. Check
adb shell dumpsys activity activities | grep "Hist #": twoMainActivityrecords are listed.
Workaround 🛠️
Declare a launch mode that reuses the running instance on the app's MainActivity:
[Activity(
Exported = true,
MainLauncher = true,
LaunchMode = Android.Content.PM.LaunchMode.SingleTask)](I only verified the equivalent FLAG_ACTIVITY_SINGLE_TOP intent flag at runtime, which gives the same single-instance result. Note #18325 reports a blank UI with SingleTask when relaunching a persistently-backgrounded app, so the right default should be checked against that scenario as well.)
Renderer 🎨
Skia
Affected platforms 📱💻🖥️
Android
Uno.Sdk version (and other relevant versions) 📦
master at 47267e7 (net10.0-android, .NET SDK 10.0.400). The runtime observation above was made on master slightly earlier (f06c45a) with a control build; the code paths below were re-checked by inspection on 47267e7. I did not re-run the emulator for this report.
IDE version 🧑💻
N/A (command line)
Anything else we need to know? 💬
- No app head or solution template in the repo declares a
LaunchMode(SamplesApp, template), and the protocol activation doc does not mention it, so anyone following the documented Android steps hits this. ApplicationActivityonly has a bare[Activity(...)]withoutLaunchMode(source);OnNewIntentis here.- Separate, smaller problem on the same path:
OnCreatearms the first-frame gate (L263) andActivationPreDrawListener.OnPreDraw(source) cancels draws until_contentViewAttachedToWindowis set. That explains the missing z-order on the stacked instance, but fixing it alone does not help: the window still belongs to the other instance, so the screen stays black. - Suggested fix: pick a reuse launch mode and document it in the protocol activation article (and ideally set it in the templates). A fix is in progress for the first-frame gate part only.
Activity
fix(android): Hand the window back from a stacked activity
fix(android): Hand the window back from a stacked activity
fix(android): Hand the window back from a stacked activity
fix(android): Hand the window back from a stacked activity
fix(android): Hand the window back from a stacked activity
fix(android): Hand the window back from a stacked activity
fix(android): Hand the window back from a stacked activity
fix(android): Hand the window back from a stacked activity