1

I'm working on a Xamarin Android project where I'd like to have activities as different starting points (e.g. app1 and app2). To achieve this I've added the option "MainLauncher = true" to the Activity-Attribute of those activities which seemed to work fine in the beginning:

[Activity(
    Label = "App1", 
    Icon = "@drawable/app1_app_icon", 
    MainLauncher = true
)]

The issue now is, that if I open app1, go back to the menu screen - withtout closing it - and open app2 at the same time, the already running app1 is displayed. App2 is not started. This is not what I've expected to happen.

Is there a way to make it work in a way that app2 gets also started at the same time as app1 is running?

I know that it is possible to start one activity multiple times but this is not what I want. Each activity should only be started once.

snytek
  • 343
  • 1
  • 9

1 Answers1

2

The solution is to define an additional attribute called TaskAffinity defining the activity that should be opened.

For App1 you would define:

[Activity(
    Label = "App1", 
    Icon = "@drawable/app1_app_icon", 
    MainLauncher = true,
    TaskAffinity = "com.company.project.actApp1"
)]

For App2 you just change the string to:

[Activity(
    Label = "App2", 
    Icon = "@drawable/app2_app_icon", 
    MainLauncher = true,
    TaskAffinity = "com.company.project.actApp2"
)]

There is also another stackoverflow question that treats this topic of TaskAffinity:

Two main activities in AndroidManifest.xml

The best explanation of what TaskAffinity I could find is also a stackoverflow question:

Android Task Affinity Explanation

Community
  • 1
  • 1
snytek
  • 343
  • 1
  • 9