Multiple Launched Activity in an Application Class

Hello all,

First of all I am not sure how I can explain it but I will try my best. So there is an android application which has multiple activities but somehow some activities appears like applications. Thats means, there is only one solution and when I deploy, I see 5 applications in the device and actually they are not applications they are activities.. I do not know what is this logic/concept. The app has already written by someone and I am new in the company.

So, the app requeries several permissions and I want permission request in the common starting class which is the application class. In my context I call MyApplicationClass. I call these 5 applications as App1, App2, App3, App4 and App5. Here is the screenshot.

And the lifecycle works as follow: when I touch App1, firstly OnCreate of myApplicationClass is executed and after that, Oncreate method of the App1's activity is executed..
If I touch app2 app in the device, then again firstly Oncreate method of myapplicationclass is executed and then OnCreate method of the App2's activity is executed.

All activities are in the same project!

So what I want to do.. I want to request necessary permissions before the activities have been loaded because oncreate, onresume and oncreateOption methods and they have many codes.. I have to change a lot of things. Thats why I want to ask required permissions in the myapplication class. The application class does not have Activity, so its difficult to ask a permission. Thats why I want to replace with something common activity which is mysplashscreen.

Scenerio 1:

I can set mysplashscreen as the mainluncher and I can ask permission and then I can start the target activity.. In theory it seems it can work. This is the best way for me, its easy and I already made actually but my problem is this:

User executes App1 but App1's activity will be not loaded because the MainLauncher is now splashscreen. So somehow I need to find out App1's activity name. If I can find it then I can start this activity in the mysplashscreen.
If user executes the app2 then it will not load app2's activitiy because the mainlauncher is splashscreen but again i'll need what the user touched. Somehow I have to find this name.

As I understand, the logic has been found in mainlauncher. but it my concept, its not mainlauncher, its what the user touched.

I did a lot of search and tried many things, never ever see app1 or app2 or others activity name in the myapplication class. I just find what is the mainlauncher, not what is touched.

Scenerio 2:

This is currently what I made but I do not like it. So I do not set mysplashscreen as mainlauncher. that means when the user touch the app1, in myapplicationclass will start app1's activity.. my logic is that start to splashscreen activity in the mymainapplication class and at the same time let load app1's activity but in the oncreate method of the app1, control whether permission ok or not, if not then close the activity and only splashscreen's activity left as loaded. And let the splashscreen shows permission request windows.. If user gives permissions then make a global static variable true and start app1's activity. (I hold the activity type which will be started). If I show as a code..

public class MyApplicationClass: Application
    public static Type LaunchedAppType;
    public static bool IsCloseApp = true;

    public override void OnCreate()
         Intent intent= packageManager.GetLaunchIntentForPackage("");
        ComponentName componentName = intent.Component;

        var classnamee= componentName.ClassName;

        if (classnamee.Contains("App1Class"))
            LaunchedAppType = typeof(App1Class);
        else if (classnamee.Contains("App2Class"))
            LaunchedAppType = typeof(App2Class);
        else if (classnamee.Contains("App3Class"))
            LaunchedAppType = typeof(App3Class);
        else if (classnamee.Contains("App4Class"))
            LaunchedAppType = typeof(App4Class);
          LaunchedAppType = typeof(App5Class);

          Intent intent = new Intent(this, typeof(SplashActivity));
         Task.Run(() => Android.App.Application.Context.StartActivity(intent));  //without task,also same         



in my app1's activity

   public class actScannerOverview : AppCompatActivity
        if (SmartSuiteApp.IsCloseApp) //close the app because no permission given yet

            var activity = (Activity)this;

          // code for initializing the app...


and my splash activity

 [Activity(Theme = "@style/MyTheme.Splash", MainLauncher = false, NoHistory = true)]
 public class SplashActivity : AppCompatActivity
           protected override void OnCreate(Bundle savedInstanceState)


     private async void MakePermissionRequests()

        await Task.Run(() => RequestPermission(Permission.Storage));

    private async void RequestPermission(Permission requestedPermission)
            var status = await CrossPermissions.Current.CheckPermissionStatusAsync(requestedPermission);
            if (status != PermissionStatus.Granted)

                var results = await CrossPermissions.Current.RequestPermissionsAsync(requestedPermission);
                status = results[requestedPermission];

            if (status == PermissionStatus.Granted)  
                SmartSuiteApp.IsCloseApp = false;
                this.FinishAffinity(); //close the splashscreen
                StartActivity(new Intent(Application.Context, SmartSuiteApp.LaunchedAppType));  //start the app what user choose

            else //if no permission then show a message and close the app

        catch (Exception ex) { ...   }

    private void ShowMessageAndCloseApp()

So this logic somehow working (not tested for all app2,app3 but seems it should work).

My questions:
1- I want to do scenerio 1. How I can get the name what user touched?
2- If scenerio 1 is not possible then what do you think about scenerio 2?

PS: I use Xamarin plugin called Plugin.Permissions for requesting permissions.


  • jezhjezh Member, Xamarin Team Xamurai

    Why are you used multiple Launched Activity? Normally, this is not the case.
    You can set mysplashscreen as mainlauncher only .

        [Activity(Label = "mysplashscreen", MainLauncher = true)]

    Other activities:

        [Activity(Label = "Activity other", MainLauncher = false)]
  • unbalancedunbalanced Member ✭✭

    @jezh, then how you will understand which application has been touched? Because if you set splashscreen as MainLauncher then you have to know which activity you should start. As I understand the problem is here, when you touch an icon on the device, you cannot know which icon has been touched and all icons actually come from the same project but different activities.

  • unbalancedunbalanced Member ✭✭
    edited October 2018

    any update?

  • PainiRogerPainiRoger CHMember ✭✭

    The problem has not been yet solved... any idea?

  • PainiRogerPainiRoger CHMember ✭✭

    still no solution found...

  • PainiRogerPainiRoger CHMember ✭✭

    I'll not give up until I find the answer :smile: up

Sign In or Register to comment.