Skip to content

Commit

Permalink
Add activity-alias support (#9654)
Browse files Browse the repository at this point in the history
Context: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/2305723
Context: https://github.com/mattleibow/MauiAppWithMultipleIcons

Apparently launching an activity-alias was not supported at all. That
probably means very few people use it, however we really should be
able to launch them.

The changes to `android-platform-support` include the ability for
`GetAndroidActivityName` to find `activity-alias` elements which have
the correct metadata. This allows us to launch them via the typical
`Run` command to launch them. 

Added a unit test.

Bump to DevDiv/android-platform-support/main@cc26de2b

* Merged PR 595972: Add support for activity-alias...
  • Loading branch information
dellis1972 authored Jan 22, 2025
1 parent 108f7a3 commit fed4208
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .external
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DevDiv/android-platform-support:main@3b4e16f197ff3e102ffb59af0b0f056046cc7658
DevDiv/android-platform-support:main@cc26de2b33292462ab2daa70c593c78ef2a241e7
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace ${ROOT_NAMESPACE}
{
[Register ("${JAVA_PACKAGENAME}.MainActivity"), Activity (Label = "${PROJECT_NAME}", MainLauncher = true, Icon = "@drawable/icon")]
//${ATTRIBUTES}
public class MainActivity : Activity
{
//${FIELDS}
Expand Down
27 changes: 27 additions & 0 deletions tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,33 @@ public void DotNetRun ([Values (true, false)] bool isRelease)
Assert.IsTrue (didLaunch, "Activity should have started.");
}

[Test]
public void ActivityAliasRuns ([Values (true, false)] bool isRelease)
{
var proj = new XamarinAndroidApplicationProject {
IsRelease = isRelease
};
proj.AndroidManifest = proj.AndroidManifest.Replace ("</application>", @"
<activity-alias
android:name="".MainActivityAlias""
android:enabled=""true""
android:icon=""@drawable/icon""
android:targetActivity="".MainActivity""
android:exported=""true"">
<intent-filter>
<action android:name=""android.intent.action.MAIN"" />
<category android:name=""android.intent.category.LAUNCHER"" />
</intent-filter>
</activity-alias>
</application>");
proj.MainActivity = proj.DefaultMainActivity.Replace ("//${ATTRIBUTES}",$"[Register(\"{proj.PackageName}.MainActivity\")]").Replace("MainLauncher = true", "MainLauncher = false");
using var builder = CreateApkBuilder ();
Assert.IsTrue (builder.Install (proj), "Install should have succeeded.");
RunProjectAndAssert (proj, builder);
Assert.True (WaitForActivityToStart (proj.PackageName, "MainActivityAlias",
Path.Combine (Root, builder.ProjectDirectory, "logcat.log"), 30), "Activity MainActivityAlias should have started.");
}

[Test]
public void NativeAssemblyCacheWithSatelliteAssemblies ([Values (true, false)] bool enableMarshalMethods)
{
Expand Down

0 comments on commit fed4208

Please sign in to comment.