First I start Activity
with FLAG_ACTIVITY_NEW_TASK
,then using command 'adb shell dumpsys Activity
',finally i find the two activities in one task。
Intent intent = new Intent(this, Main2Activity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
These Activity
were normal, i didn't modify them。These were stack information.
ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
Display #0 (activities from top to bottom):
Stack #1:
mFullscreen=true
mBounds=null
Task id #2493
mFullscreen=true
mBounds=null
mMinWidth=-1
mMinHeight=-1
mLastNonFullscreenBounds=null
* TaskRecord{cb64df8 #2493 A=com.example.flag U=0 StackId=1 sz=2}
userId=0 effectiveUid=u0a63 mCallingUid=2000 mUserSetupComplete=true mCallingPackage=null
affinity=com.example.flag
intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.flag/.MainActivity}
realActivity=com.example.flag/.MainActivity
autoRemoveRecents=false isPersistable=true numFullscreen=2 taskType=0 mTaskToReturnTo=1
rootWasReset=false mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE
Activities=[ActivityRecord{b786d24 u0 com.example.flag/.MainActivity t2493}, ActivityRecord{afe6f61 u0 com.example.flag/.Main2Activity t2493}]
askedCompatMode=false inRecents=true isAvailable=true
lastThumbnail=null lastThumbnailFile=/data/system_ce/0/recent_images/2493_task_thumbnail.png
stackId=1
hasBeenVisible=true mResizeMode=RESIZE_MODE_RESIZEABLE isResizeable=true firstActiveTime=1499670460422 lastActiveTime=1499670460422 (inactive for 23s)
* Hist #1: ActivityRecord{afe6f61 u0 com.example.flag/.Main2Activity t2493}
packageName=com.example.flag processName=com.example.flag
launchedFromUid=10063 launchedFromPackage=com.example.flag userId=0
app=ProcessRecord{b30f2d1 11785:com.example.flag/u0a63}
Intent { flg=0x10000000 cmp=com.example.flag/.Main2Activity }
frontOfTask=false task=TaskRecord{cb64df8 #2493 A=com.example.flag U=0 StackId=1 sz=2}
taskAffinity=com.example.flag
realActivity=com.example.flag/.Main2Activity
baseDir=/data/app/com.example.flag-1/base.apk
dataDir=/data/user/0/com.example.flag
stateNotNeeded=false componentSpecified=true mActivityType=0
compat={480dpi} labelRes=0x7f060021 icon=0x7f030000 theme=0x7f0800a3
config={1.0 460mcc1mnc [zh_CN_#Hans,en_US,zh_TW_#Hant] ldltr sw360dp w360dp h616dp 480dpi nrml long port finger -keyb/v/h -nav/h s.8}
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=-23s446ms
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_NOT_SHOWN
fullscreen=true noDisplay=false immersive=false launchMode=0
frozenBeforeDestroy=false forceNewConfig=false
mActivityType=APPLICATION_ACTIVITY_TYPE
waitingVisible=false nowVisible=true lastVisibleTime=-22s952ms
resizeMode=RESIZE_MODE_RESIZEABLE
* Hist #0: ActivityRecord{b786d24 u0 com.example.flag/.MainActivity t2493}
packageName=com.example.flag processName=com.example.flag
launchedFromUid=2000 launchedFromPackage=null userId=0
app=ProcessRecord{b30f2d1 11785:com.example.flag/u0a63}
Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.flag/.MainActivity }
frontOfTask=true task=TaskRecord{cb64df8 #2493 A=com.example.flag U=0 StackId=1 sz=2}
taskAffinity=com.example.flag
realActivity=com.example.flag/.MainActivity
baseDir=/data/app/com.example.flag-1/base.apk
dataDir=/data/user/0/com.example.flag
stateNotNeeded=false componentSpecified=true mActivityType=0
compat={480dpi} labelRes=0x7f060021 icon=0x7f030000 theme=0x7f0800a3
config={1.0 460mcc1mnc [zh_CN_#Hans,en_US,zh_TW_#Hant] ldltr sw360dp w360dp h616dp 480dpi nrml long port finger -keyb/v/h -nav/h s.8}
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=-57s646ms
haveState=true icicle=Bundle[mParcelledData.dataSize=604]
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=-56s921ms
resizeMode=RESIZE_MODE_RESIZEABLE
flag — FLAG_ACTIVITY_CLEAR_TOP: If the Activity being started is already running in the current task then instead of launching the new instance of that Activity, all the other activities on top of it is destroyed (with call to onDestroy method) and this intent is delivered to the resumed instance of the Activity (now ...
You can just use this code: Intent myIntent= new Intent(FirstActivity. this,SecondActivity. class); startActivity(myIntent);
When the intent that launches an activity contains the FLAG_ACTIVITY_NEW_TASK flag. A new activity is, by default, launched into the task of the activity that called startActivity() . contains the FLAG_ACTIVITY_NEW_TASK flag, the system looks for a different task to house the new activity.
In order to decide what action to take in your activity, you can read the Intent that was used to start it. As your activity starts, call getIntent() to retrieve the Intent that started the activity.
You need to add combination of flags:
Intent intent = new Intent(this, Main2Activity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
startActivity(intent);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With