adb shell dumpsys activity activities shows two instances of single task in separate stack
Asked Answered
S

0

5

I have a main activity having intent with CATEGORY_HOME to behave like a launcher. It also has CATEGORY_LAUNCHER so that user can access from App Drawer. Here is the main activity:

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}

I have another activity containing a button to call the MainActivity with HOME intent. It is another entry point from App Drawer. Here is the Test Activity:

public class TestActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);
    findViewById(R.id.btn_test).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(TestActivity.this, MainActivity.class);
            intent.setAction(Intent.ACTION_MAIN);
            intent.addCategory(Intent.CATEGORY_HOME);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    });
}
}

Here is the AndroidManifest.xml:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:launchMode="singleTask"
        android:clearTaskOnLaunch="true"
        android:stateNotNeeded="true"
        android:windowSoftInputMode="adjustPan"
        android:screenOrientation="nosensor"
        android:resumeWhilePausing="true"
        android:taskAffinity=""
        android:enabled="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.HOME" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".TestActivity"
        android:label="Test Launcher">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

After installing, app is opened from App Drawer. Then Home button is pressed and multiple options for Launcher comes. On selection this one, again MainActivity appears. Later, by going to different launcher Test Activity is opened from App Drawer. From there, button is clicked to open the MainActivity as launcher. The issue is that even if MainActivity is singleTask, it has entry in two different stacks. Here is the logs obtained by:

adb shell dumpsys activity activities

ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
  Display #0 (activities from top to bottom):
  Stack #1:
  mFullscreen=true
  mBounds=null
    Task id #1352
    mFullscreen=true
    mBounds=null
    mMinWidth=-1
    mMinHeight=-1
    mLastNonFullscreenBounds=null
    * TaskRecord{90b88b8 #1352 I=com.example.binay.launcherdemo/.MainActivity U=0 StackId=1 sz=1}
      userId=0 effectiveUid=u0a894 mCallingUid=u0a894 mUserSetupComplete=true mCallingPackage=com.example.binay.launcherdemo
      intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.binay.launcherdemo/.MainActivity}
      realActivity=com.example.binay.launcherdemo/.MainActivity
      autoRemoveRecents=false isPersistable=true numFullscreen=1 taskType=0 mTaskToReturnTo=0
      rootWasReset=false mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE
      Activities=[ActivityRecord{b1b0736 u0 com.example.binay.launcherdemo/.MainActivity t1352}]
      askedCompatMode=false inRecents=true isAvailable=true
      lastThumbnail=null lastThumbnailFile=/data/system_ce/0/recent_images/1352_task_thumbnail.png
      stackId=1
      hasBeenVisible=true mResizeMode=RESIZE_MODE_RESIZEABLE isResizeable=true firstActiveTime=1532172058626 lastActiveTime=1532172058626 (inactive for 4s)
      * Hist #0: ActivityRecord{b1b0736 u0 com.example.binay.launcherdemo/.MainActivity t1352}
          packageName=com.example.binay.launcherdemo processName=com.example.binay.launcherdemo
          launchedFromUid=10894 launchedFromPackage=com.example.binay.launcherdemo userId=0
          app=ProcessRecord{3e17691 9030:com.example.binay.launcherdemo/u0a894}
          Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x10408000 cmp=com.example.binay.launcherdemo/.MainActivity }
          frontOfTask=true task=TaskRecord{90b88b8 #1352 I=com.example.binay.launcherdemo/.MainActivity U=0 StackId=1 sz=1}
          taskAffinity=null
          realActivity=com.example.binay.launcherdemo/.MainActivity
          baseDir=/data/app/com.example.binay.launcherdemo-1/base.apk
          dataDir=/data/user/0/com.example.binay.launcherdemo
          stateNotNeeded=true componentSpecified=true mActivityType=0
          compat={320dpi} labelRes=0x7f0b0027 icon=0x7f0a0000 theme=0x7f0c0005
          config={1.0 ?mcc?mnc [en_IN,ta_IN] ldltr sw360dp w360dp h616dp 320dpi nrml long port finger -keyb/v/h -nav/h s.6}
          taskConfigOverride={1.0 ?mcc?mnc ?localeList ?layoutDir ?swdp ?wdp ?hdp ?density ?lsize ?long ?orien ?uimode ?night ?touch ?keyb/?/? ?nav/?}
          taskDescription: iconFilename=null label="null" color=ff3f51b5
          launchFailed=false launchCount=1 lastLaunchTime=-4s516ms
          haveState=false icicle=null
          state=RESUMED stopped=false delayedResume=false finishing=false
          keysPaused=false inHistory=true visible=true sleeping=false idle=true mStartingWindowState=STARTING_WINDOW_SHOWN
          fullscreen=true noDisplay=false immersive=false launchMode=2
          frozenBeforeDestroy=false forceNewConfig=false
          mActivityType=APPLICATION_ACTIVITY_TYPE
          waitingVisible=false nowVisible=true lastVisibleTime=-3s687ms
          resizeMode=RESIZE_MODE_RESIZEABLE
    Task id #1358
    mFullscreen=true
    mBounds=null
    mMinWidth=-1
    mMinHeight=-1
    mLastNonFullscreenBounds=null
    * TaskRecord{e45d9f6 #1358 A=com.example.binay.launcherdemo U=0 StackId=1 sz=1}
      userId=0 effectiveUid=u0a894 mCallingUid=u0a880 mUserSetupComplete=true mCallingPackage=com.apusapps.launcher
      affinity=com.example.binay.launcherdemo
      intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.binay.launcherdemo/.TestActivity bnds=[352,488][488,662]}
      realActivity=com.example.binay.launcherdemo/.TestActivity
      autoRemoveRecents=false isPersistable=true numFullscreen=1 taskType=0 mTaskToReturnTo=0
      rootWasReset=true mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE
      Activities=[ActivityRecord{bcd0adc u0 com.example.binay.launcherdemo/.TestActivity t1358}]
      askedCompatMode=false inRecents=true isAvailable=true
      lastThumbnail=android.graphics.Bitmap@66af1f7 lastThumbnailFile=/data/system_ce/0/recent_images/1358_task_thumbnail.png
      stackId=1
      hasBeenVisible=true mResizeMode=RESIZE_MODE_RESIZEABLE isResizeable=true firstActiveTime=1532172058621 lastActiveTime=1532172058621 (inactive for 4s)
      * Hist #0: ActivityRecord{bcd0adc u0 com.example.binay.launcherdemo/.TestActivity t1358}
          packageName=com.example.binay.launcherdemo processName=com.example.binay.launcherdemo
          launchedFromUid=10880 launchedFromPackage=com.apusapps.launcher userId=0
          app=ProcessRecord{3e17691 9030:com.example.binay.launcherdemo/u0a894}
          Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.example.binay.launcherdemo/.TestActivity bnds=[352,488][488,662] }
          frontOfTask=true task=TaskRecord{e45d9f6 #1358 A=com.example.binay.launcherdemo U=0 StackId=1 sz=1}
          taskAffinity=com.example.binay.launcherdemo
          realActivity=com.example.binay.launcherdemo/.TestActivity
          baseDir=/data/app/com.example.binay.launcherdemo-1/base.apk
          dataDir=/data/user/0/com.example.binay.launcherdemo
          stateNotNeeded=false componentSpecified=true mActivityType=0
          compat={320dpi} labelRes=0x0 icon=0x7f0a0000 theme=0x7f0c0005
          config={1.0 ?mcc?mnc [en_IN,ta_IN] ldltr sw360dp w360dp h616dp 320dpi nrml long port finger -keyb/v/h -nav/h s.6}
          taskConfigOverride={1.0 ?mcc?mnc ?localeList ?layoutDir ?swdp ?wdp ?hdp ?density ?lsize ?long ?orien ?uimode ?night ?touch ?keyb/?/? ?nav/?}
          taskDescription: iconFilename=null label="null" color=ff3f51b5
          launchFailed=false launchCount=0 lastLaunchTime=-5s605ms
          haveState=true icicle=Bundle[mParcelledData.dataSize=1064]
          state=STOPPED stopped=true delayedResume=false finishing=false
          keysPaused=false inHistory=true visible=false sleeping=false idle=true mStartingWindowState=STARTING_WINDOW_SHOWN
          fullscreen=true noDisplay=false immersive=false launchMode=0
          frozenBeforeDestroy=false forceNewConfig=false
          mActivityType=APPLICATION_ACTIVITY_TYPE
          waitingVisible=false nowVisible=false lastVisibleTime=-5s221ms
          resizeMode=RESIZE_MODE_RESIZEABLE
    Task id #1357
    mFullscreen=true
    mBounds=null
    mMinWidth=-1
    mMinHeight=-1
    mLastNonFullscreenBounds=null
    * TaskRecord{d4c7864 #1357 A=com.apusapps.launcher U=0 StackId=1 sz=1}
      userId=0 effectiveUid=u0a880 mCallingUid=u0a880 mUserSetupComplete=true mCallingPackage=com.apusapps.launcher
      affinity=com.apusapps.launcher
      intent={act=android.intent.action.MAIN flg=0x18000000 cmp=com.apusapps.launcher/com.apusapps.allapps.AllAppsActivity}
      realActivity=com.apusapps.launcher/com.apusapps.allapps.AllAppsActivity
      autoRemoveRecents=false isPersistable=true numFullscreen=1 taskType=0 mTaskToReturnTo=1
      rootWasReset=false mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE
      Activities=[ActivityRecord{21fe202 u0 com.apusapps.launcher/com.apusapps.allapps.AllAppsActivity t1357}]
      askedCompatMode=false inRecents=true isAvailable=true
      lastThumbnail=android.graphics.Bitmap@795eacd lastThumbnailFile=/data/system_ce/0/recent_images/1357_task_thumbnail.png
      stackId=1
      hasBeenVisible=true mResizeMode=RESIZE_MODE_UNRESIZEABLE isResizeable=false firstActiveTime=1532172057464 lastActiveTime=1532172057464 (inactive for 5s)
      * Hist #0: ActivityRecord{21fe202 u0 com.apusapps.launcher/com.apusapps.allapps.AllAppsActivity t1357}
          packageName=com.apusapps.launcher processName=com.apusapps.launcher
          launchedFromUid=10880 launchedFromPackage=com.apusapps.launcher userId=0
          app=ProcessRecord{f590a8b 7920:com.apusapps.launcher/u0a880}
          Intent { act=android.intent.action.MAIN flg=0x18000000 cmp=com.apusapps.launcher/com.apusapps.allapps.AllAppsActivity bnds=[288,1098][428,1280] (has extras) }
          frontOfTask=true task=TaskRecord{d4c7864 #1357 A=com.apusapps.launcher U=0 StackId=1 sz=1}
          taskAffinity=com.apusapps.launcher
          realActivity=com.apusapps.launcher/com.apusapps.allapps.AllAppsActivity
          baseDir=/data/app/com.apusapps.launcher-1/base.apk
          dataDir=/data/user/0/com.apusapps.launcher
          stateNotNeeded=false componentSpecified=true mActivityType=0
          compat={320dpi} labelRes=0x7f08005f icon=0x7f0200a3 theme=0x7f1101c1
          config={1.0 ?mcc?mnc [en_IN,ta_IN] ldltr sw360dp w360dp h616dp 320dpi nrml long port finger -keyb/v/h -nav/h s.6}
          taskConfigOverride={1.0 ?mcc?mnc ?localeList ?layoutDir ?swdp ?wdp ?hdp ?density ?lsize ?long ?orien ?uimode ?night ?touch ?keyb/?/? ?nav/?}
          taskDescription: iconFilename=null label="null" color=ff222222
          launchFailed=false launchCount=0 lastLaunchTime=-11s467ms
          haveState=true icicle=Bundle[mParcelledData.dataSize=3252]
          state=STOPPED stopped=true delayedResume=false finishing=false
          keysPaused=false inHistory=true visible=false sleeping=false idle=true mStartingWindowState=STARTING_WINDOW_NOT_SHOWN
          fullscreen=true noDisplay=false immersive=false launchMode=1
          frozenBeforeDestroy=false forceNewConfig=false
          mActivityType=APPLICATION_ACTIVITY_TYPE
          waitingVisible=false nowVisible=false lastVisibleTime=-10s793ms
          resizeMode=RESIZE_MODE_UNRESIZEABLE
    Task id #1348
    mFullscreen=true
    mBounds=null
    mMinWidth=-1
    mMinHeight=-1
    mLastNonFullscreenBounds=null
    * TaskRecord{fed9f82 #1348 A=com.apusapps.launcher U=0 StackId=1 sz=1}
      userId=0 effectiveUid=u0a880 mCallingUid=u0a880 mUserSetupComplete=true mCallingPackage=com.apusapps.launcher
      affinity=com.apusapps.launcher
      intent={act=android.intent.action.MAIN flg=0x18000000 cmp=com.apusapps.launcher/com.apusapps.allapps.AllAppsActivity}
      realActivity=com.apusapps.launcher/com.apusapps.allapps.AllAppsActivity
      autoRemoveRecents=false isPersistable=true numFullscreen=1 taskType=0 mTaskToReturnTo=1
      rootWasReset=false mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE
      Activities=[ActivityRecord{5f4526d u0 com.apusapps.launcher/com.apusapps.allapps.AllAppsActivity t1348}]
      askedCompatMode=false inRecents=false isAvailable=true
      lastThumbnail=null lastThumbnailFile=/data/system_ce/0/recent_images/1348_task_thumbnail.png
      stackId=1
      hasBeenVisible=true mResizeMode=RESIZE_MODE_UNRESIZEABLE isResizeable=false firstActiveTime=1532172010058 lastActiveTime=1532172010058 (inactive for 53s)
      * Hist #0: ActivityRecord{5f4526d u0 com.apusapps.launcher/com.apusapps.allapps.AllAppsActivity t1348}
          packageName=com.apusapps.launcher processName=com.apusapps.launcher
          launchedFromUid=10880 launchedFromPackage=com.apusapps.launcher userId=0
          app=ProcessRecord{f590a8b 7920:com.apusapps.launcher/u0a880}
          Intent { act=android.intent.action.MAIN flg=0x18000000 cmp=com.apusapps.launcher/com.apusapps.allapps.AllAppsActivity bnds=[288,1098][428,1280] (has extras) }
          frontOfTask=true task=TaskRecord{fed9f82 #1348 A=com.apusapps.launcher U=0 StackId=1 sz=1}
          taskAffinity=com.apusapps.launcher
          realActivity=com.apusapps.launcher/com.apusapps.allapps.AllAppsActivity
          baseDir=/data/app/com.apusapps.launcher-1/base.apk
          dataDir=/data/user/0/com.apusapps.launcher
          stateNotNeeded=false componentSpecified=true mActivityType=0
          compat={320dpi} labelRes=0x7f08005f icon=0x7f0200a3 theme=0x7f1101c1
          config={1.0 ?mcc?mnc [en_IN,ta_IN] ldltr sw360dp w360dp h616dp 320dpi nrml long port finger -keyb/v/h -nav/h s.6}
          taskConfigOverride={1.0 ?mcc?mnc ?localeList ?layoutDir ?swdp ?wdp ?hdp ?density ?lsize ?long ?orien ?uimode ?night ?touch ?keyb/?/? ?nav/?}
          taskDescription: iconFilename=null label="null" color=ff222222
          launchFailed=false launchCount=0 lastLaunchTime=-2m24s974ms
          haveState=true icicle=Bundle[mParcelledData.dataSize=3252]
          state=STOPPED stopped=true delayedResume=false finishing=false
          keysPaused=false inHistory=true visible=false sleeping=false idle=true mStartingWindowState=STARTING_WINDOW_NOT_SHOWN
          fullscreen=true noDisplay=false immersive=false launchMode=1
          frozenBeforeDestroy=false forceNewConfig=false
          mActivityType=APPLICATION_ACTIVITY_TYPE
          waitingVisible=false nowVisible=false lastVisibleTime=-1m52s149ms
          resizeMode=RESIZE_MODE_UNRESIZEABLE

    Running activities (most recent first):
      TaskRecord{90b88b8 #1352 I=com.example.binay.launcherdemo/.MainActivity U=0 StackId=1 sz=1}
        Run #5: ActivityRecord{b1b0736 u0 com.example.binay.launcherdemo/.MainActivity t1352}
      TaskRecord{e45d9f6 #1358 A=com.example.binay.launcherdemo U=0 StackId=1 sz=1}
        Run #4: ActivityRecord{bcd0adc u0 com.example.binay.launcherdemo/.TestActivity t1358}
      TaskRecord{d4c7864 #1357 A=com.apusapps.launcher U=0 StackId=1 sz=1}
        Run #3: ActivityRecord{21fe202 u0 com.apusapps.launcher/com.apusapps.allapps.AllAppsActivity t1357}
      TaskRecord{fed9f82 #1348 A=com.apusapps.launcher U=0 StackId=1 sz=1}
        Run #2: ActivityRecord{5f4526d u0 com.apusapps.launcher/com.apusapps.allapps.AllAppsActivity t1348}
      TaskRecord{14ab4fc #1329 A=com.android.settings U=0 StackId=1 sz=2}
        Run #1: ActivityRecord{34e44db u0 com.android.settings/.SubSettings t1329}
        Run #0: ActivityRecord{8cc3587 u0 com.android.settings/.Settings t1329}

    mResumedActivity: ActivityRecord{b1b0736 u0 com.example.binay.launcherdemo/.MainActivity t1352}
    mLastPausedActivity: ActivityRecord{bcd0adc u0 com.example.binay.launcherdemo/.TestActivity t1358}

  Stack #0:
  mFullscreen=true
  mBounds=null
    Task id #1354
    mFullscreen=true
    mBounds=null
    mMinWidth=-1
    mMinHeight=-1
    mLastNonFullscreenBounds=null
    * TaskRecord{28ab6d0 #1354 I=com.example.binay.launcherdemo/.MainActivity U=0 StackId=0 sz=1}
      userId=0 effectiveUid=u0a894 mCallingUid=1000 mUserSetupComplete=true mCallingPackage=android
      intent={act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x13200000 cmp=com.example.binay.launcherdemo/.MainActivity}
      realActivity=com.example.binay.launcherdemo/.MainActivity
      autoRemoveRecents=false isPersistable=true numFullscreen=1 taskType=1 mTaskToReturnTo=0
      rootWasReset=true mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE
      Activities=[ActivityRecord{63afa71 u0 com.example.binay.launcherdemo/.MainActivity t1354}]
      askedCompatMode=false inRecents=true isAvailable=true
      lastThumbnail=null lastThumbnailFile=/data/system_ce/0/recent_images/1354_task_thumbnail.png
      stackId=0
      hasBeenVisible=true mResizeMode=RESIZE_MODE_RESIZEABLE isResizeable=false firstActiveTime=1532172047076 lastActiveTime=1532172047076 (inactive for 16s)
      * Hist #0: ActivityRecord{63afa71 u0 com.example.binay.launcherdemo/.MainActivity t1354}
          packageName=com.example.binay.launcherdemo processName=com.example.binay.launcherdemo
          launchedFromUid=1000 launchedFromPackage=android userId=0
          app=ProcessRecord{3e17691 9030:com.example.binay.launcherdemo/u0a894}
          Intent { act=android.intent.action.MAIN cat=[android.intent.category.HOME] flg=0x13200000 cmp=com.example.binay.launcherdemo/.MainActivity (has extras) }
          frontOfTask=true task=TaskRecord{28ab6d0 #1354 I=com.example.binay.launcherdemo/.MainActivity U=0 StackId=0 sz=1}
          taskAffinity=null
          realActivity=com.example.binay.launcherdemo/.MainActivity
          baseDir=/data/app/com.example.binay.launcherdemo-1/base.apk
          dataDir=/data/user/0/com.example.binay.launcherdemo
          stateNotNeeded=true componentSpecified=true mActivityType=1
          compat={320dpi} labelRes=0x7f0b0027 icon=0x7f0a0000 theme=0x7f0c0005
          config={1.0 ?mcc?mnc [en_IN,ta_IN] ldltr sw360dp w360dp h616dp 320dpi nrml long port finger -keyb/v/h -nav/h s.6}
          taskConfigOverride={1.0 ?mcc?mnc ?localeList ?layoutDir ?swdp ?wdp ?hdp ?density ?lsize ?long ?orien ?uimode ?night ?touch ?keyb/?/? ?nav/?}
          taskDescription: iconFilename=null label="null" color=ff3f51b5
          launchFailed=false launchCount=0 lastLaunchTime=-25s581ms
          haveState=true icicle=Bundle[mParcelledData.dataSize=988]
          state=STOPPED stopped=true delayedResume=false finishing=false
          keysPaused=false inHistory=true visible=false sleeping=false idle=true mStartingWindowState=STARTING_WINDOW_SHOWN
          fullscreen=true noDisplay=false immersive=false launchMode=2
          frozenBeforeDestroy=false forceNewConfig=false
          mActivityType=HOME_ACTIVITY_TYPE
          waitingVisible=false nowVisible=false lastVisibleTime=-24s580ms
          resizeMode=RESIZE_MODE_RESIZEABLE

    Running activities (most recent first):
      TaskRecord{f52b693 #1347 A=com.apusapps.launcher U=0 StackId=0 sz=1}
        Run #2: ActivityRecord{ea77784 u0 com.apusapps.launcher/.launcher.ApusLauncherActivity t1347}
      TaskRecord{28ab6d0 #1354 I=com.example.binay.launcherdemo/.MainActivity U=0 StackId=0 sz=1}
        Run #1: ActivityRecord{63afa71 u0 com.example.binay.launcherdemo/.MainActivity t1354}
      TaskRecord{2f08c58 #1344 A=com.teslacoilsw.launcher.NovaLauncher U=0 StackId=0 sz=1}
        Run #0: ActivityRecord{bedac0b u0 com.teslacoilsw.launcher/.NovaLauncher t1344}

    mLastPausedActivity: ActivityRecord{ea77784 u0 com.apusapps.launcher/.launcher.ApusLauncherActivity t1347}

  mFocusedActivity: ActivityRecord{b1b0736 u0 com.example.binay.launcherdemo/.MainActivity t1352}
  mFocusedStack=ActivityStack{bd7e9da stackId=1, 6 tasks} mLastFocusedStack=ActivityStack{bd7e9da stackId=1, 6 tasks}
  mSleepTimeout=false
  mCurTaskIdForUser={0=1358}
  mUserStackInFront={}
  mActivityContainers={0=ActivtyContainer{0}A, 1=ActivtyContainer{1}A}
  mLockTaskModeState=NONE mLockTaskPackages (userId:packages)=
    0:[]
    10:[]
    11:[]
 mLockTaskModeTasks[]

Two entries of MainActivity is there in the logs. One with stackId=0 and another with stackId=1. So, why two instances are created even if the activity is singleTask?

Salubrious answered 21/7, 2018 at 11:49 Comment(10)
what do you see if you add Log.d inside MainActivity#onCreate method? do you see it twice in the logcat?Cannibal
Yes, onCreate is called again.Salubrious
OK so add it also in onDestroy and check if onCreate is called twice without onDestroy being calledCannibal
I have put logs in onDestroy also. It does not gets called.Salubrious
I have tried destroying the previous instance also if onCreate gets called. But in Android 7.0 onwards, if called from different places like here, pressing home button or calling from TestActivity, onCreate is called again. If instance is destroyed from stackId=1, then on calling from TestActivity it creates again. Similar is the case for stackId=0Salubrious
Till Android 6.0, if previous instance is destroyed, it uses the existing one and never creates another. But it is not supposed to create more than one instance for singleTask, right?Salubrious
hi @binay37, were you able to find the RCA. I have gotten stuck at similar problem. Tried multiple solutions but for my launcher it's not working...Tandi
@Tandi , I was not able to find the cause but found an alternative recently. Instead of passing class name in intent constructor, I passed the package name with .setPackage(context.getPackageName()) and this issue didn't happen again.Salubrious
I think I have a similar issue: #54712662Taal
@TamásBolvári , more than one instance still exists for my case. Home intent is being called from multiple places and it was switching between the two instances earlier. But with the above approach, it has not affected the functionality and it is not switching the instances.Salubrious

© 2022 - 2024 — McMap. All rights reserved.