Search code examples
androidandroid-activitybackgroundactivity-manager

why is android coming from background activity class "com.miui.home.launcher.Launcher"


While the activity is on, I go to the background and when I want to learn the classname from within a service, I see "com.miui.home.launcher.Launcher". I need the activity class. Where am I going wrong?

The codes I wrote for classname are as follows;

    ActivityManager am = (ActivityManager) 
    getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
    List<ActivityManager.RunningTaskInfo> taskInfo = am.getRunningTasks(1);
    ComponentName componentInfo = taskInfo.get(0).topActivity;
    String className = componentInfo.getClassName();

Solution

  • com.miumi.home.launcher.Launcher is Activity set as devices launcher - "desktop" app responsible for showing all your apps grid, widgets etc. when your app is in background (put there by e.g. Home button) and any of your Activites isn't present on the screen then your device is showing Launcher app and this is reporting your code

    note that getRunningTasks method is deprecated and won't let you know which third-party app is on foreground. currently this method may only return info about your app or Launcher/"desktop"

    https://developer.android.com/reference/android/app/ActivityManager#getRunningTasks(int)