Skip to content

Commit fed4208

Browse files
authored
Add activity-alias support (#9654)
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...
1 parent 108f7a3 commit fed4208

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

.external

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
DevDiv/android-platform-support:main@3b4e16f197ff3e102ffb59af0b0f056046cc7658
1+
DevDiv/android-platform-support:main@cc26de2b33292462ab2daa70c593c78ef2a241e7

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.ProjectTools/Resources/Base/MainActivity.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace ${ROOT_NAMESPACE}
1212
{
1313
[Register ("${JAVA_PACKAGENAME}.MainActivity"), Activity (Label = "${PROJECT_NAME}", MainLauncher = true, Icon = "@drawable/icon")]
14+
//${ATTRIBUTES}
1415
public class MainActivity : Activity
1516
{
1617
//${FIELDS}

tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,33 @@ public void DotNetRun ([Values (true, false)] bool isRelease)
4646
Assert.IsTrue (didLaunch, "Activity should have started.");
4747
}
4848

49+
[Test]
50+
public void ActivityAliasRuns ([Values (true, false)] bool isRelease)
51+
{
52+
var proj = new XamarinAndroidApplicationProject {
53+
IsRelease = isRelease
54+
};
55+
proj.AndroidManifest = proj.AndroidManifest.Replace ("</application>", @"
56+
<activity-alias
57+
android:name="".MainActivityAlias""
58+
android:enabled=""true""
59+
android:icon=""@drawable/icon""
60+
android:targetActivity="".MainActivity""
61+
android:exported=""true"">
62+
<intent-filter>
63+
<action android:name=""android.intent.action.MAIN"" />
64+
<category android:name=""android.intent.category.LAUNCHER"" />
65+
</intent-filter>
66+
</activity-alias>
67+
</application>");
68+
proj.MainActivity = proj.DefaultMainActivity.Replace ("//${ATTRIBUTES}",$"[Register(\"{proj.PackageName}.MainActivity\")]").Replace("MainLauncher = true", "MainLauncher = false");
69+
using var builder = CreateApkBuilder ();
70+
Assert.IsTrue (builder.Install (proj), "Install should have succeeded.");
71+
RunProjectAndAssert (proj, builder);
72+
Assert.True (WaitForActivityToStart (proj.PackageName, "MainActivityAlias",
73+
Path.Combine (Root, builder.ProjectDirectory, "logcat.log"), 30), "Activity MainActivityAlias should have started.");
74+
}
75+
4976
[Test]
5077
public void NativeAssemblyCacheWithSatelliteAssemblies ([Values (true, false)] bool enableMarshalMethods)
5178
{

0 commit comments

Comments
 (0)