作为主题,当我按下按钮时,我的应用程序返回2个活动。这是活动的重写后退按钮:
@Override
public void onBackPressed() {
if (mainNavMenu != null && mainNavMenu.getDrawerLayout().isDrawerOpen(GravityCompat.START)) {
mainNavMenu.getDrawerLayout().closeDrawers();
return;
}
super.onBackPressed();
}
这是按下按钮前的活动堆栈:
Task id #300
* TaskRecord{3470ba7b #300 A=com.package.example U=0 sz=3}
userId=0 effectiveUid=u0a199 mCallingUid=u0a199 mCallingPackage=com.package.example
affinity=com.package.example
intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.package.example/.view.SplashScreenActivity}
realActivity=com.package.example/.view.SplashScreenActivity
autoRemoveRecents=false isPersistable=true numFullscreen=3 taskType=0 mTaskToReturnTo=1
rootWasReset=false mNeverRelinquishIdentity=true mReuseTask=false
Activities=[ActivityRecord{d9eeb4e u0 com.package.example/.view.MainActivity t300}, ActivityRecord{2017cfc8 u0 com.package.example/.view.JobDetailsActivity t300}, ActivityRecord{3da3f636 u0 com.package.example/.view.WebActivity t300}]
askedCompatMode=false inRecents=true isAvailable=true
lastThumbnail=android.graphics.Bitmap@22f31098 lastThumbnailFile=/data/system/recent_images/300_task_thumbnail.png
hasBeenVisible=true firstActiveTime=1517840356492 lastActiveTime=1517840356492 (inactive for 4s)
* Hist #2: ActivityRecord{3da3f636 u0 com.package.example/.view.WebActivity t300}
packageName=com.package.example processName=com.package.example
launchedFromUid=10199 launchedFromPackage=com.package.example userId=0
app=ProcessRecord{21ce55f9 17355:com.package.example/u0a199}
Intent { cmp=com.package.example/.view.WebActivity (has extras) }
frontOfTask=false task=TaskRecord{3470ba7b #300 A=com.package.example U=0 sz=3}
taskAffinity=com.package.example
realActivity=com.package.example/.view.WebActivity
baseDir=/data/app/com.package.example-2/base.apk
dataDir=/data/data/com.package.example
stateNotNeeded=false componentSpecified=true mActivityType=0
compat={480dpi} labelRes=0x7f0d001f icon=0x7f0c0000 theme=0x7f0e0007
config={0 1.0 222mcc99mnc it_IT ldltr sw360dp w360dp h615dp 480dpi nrml long port finger -keyb/v/h -nav/h s.6}
resultTo=ActivityRecord{2017cfc8 u0 com.package.example/.view.JobDetailsActivity t300} resultWho=null resultCode=1117
taskDescription: iconFilename=null label="null" color=ffadd44b
launchFailed=false launchCount=1 lastLaunchTime=-4s170ms
haveState=false icicle=null
state=RESUMED stopped=false delayedResume=false finishing=false
keysPaused=false inHistory=true visible=true sleeping=false idle=true
fullscreen=true noDisplay=false immersive=false launchMode=0
frozenBeforeDestroy=false forceNewConfig=false
mActivityType=APPLICATION_ACTIVITY_TYPE
waitingVisible=false nowVisible=true lastVisibleTime=-3s325ms
* Hist #1: ActivityRecord{2017cfc8 u0 com.package.example/.view.JobDetailsActivity t300}
packageName=com.package.example processName=com.package.example
launchedFromUid=10199 launchedFromPackage=com.package.example userId=0
app=ProcessRecord{21ce55f9 17355:com.package.example/u0a199}
Intent { cmp=com.package.example/.view.JobDetailsActivity (has extras) }
frontOfTask=false task=TaskRecord{3470ba7b #300 A=com.package.example U=0 sz=3}
taskAffinity=com.package.example
realActivity=com.package.example/.view.JobDetailsActivity
baseDir=/data/app/com.package.example-2/base.apk
dataDir=/data/data/com.package.example
stateNotNeeded=false componentSpecified=true mActivityType=0
compat={480dpi} labelRes=0x7f0d001f icon=0x7f0c0000 theme=0x7f0e0007
config={0 1.0 222mcc99mnc it_IT ldltr sw360dp w360dp h615dp 480dpi nrml long port finger -keyb/v/h -nav/h s.6}
taskDescription: iconFilename=null label="null" color=ffadd44b
launchFailed=false launchCount=1 lastLaunchTime=-33s92ms
haveState=false icicle=null
state=STOPPING stopped=false delayedResume=false finishing=false
keysPaused=false inHistory=true visible=false sleeping=false idle=true
fullscreen=true noDisplay=false immersive=false launchMode=0
frozenBeforeDestroy=false forceNewConfig=false
mActivityType=APPLICATION_ACTIVITY_TYPE
waitingVisible=false nowVisible=false lastVisibleTime=-32s196ms
* Hist #0: ActivityRecord{d9eeb4e u0 com.package.example/.view.MainActivity t300}
packageName=com.package.example processName=com.package.example
launchedFromUid=10199 launchedFromPackage=com.package.example userId=0
app=ProcessRecord{21ce55f9 17355:com.package.example/u0a199}
Intent { flg=0x10008000 cmp=com.package.example/.view.MainActivity (has extras) }
frontOfTask=true task=TaskRecord{3470ba7b #300 A=com.package.example U=0 sz=3}
taskAffinity=com.package.example
realActivity=com.package.example/.view.MainActivity
baseDir=/data/app/com.package.example-2/base.apk
dataDir=/data/data/com.package.example
stateNotNeeded=false componentSpecified=true mActivityType=0
compat={480dpi} labelRes=0x7f0d001f icon=0x7f0c0000 theme=0x7f0e0007
config={0 1.0 222mcc99mnc it_IT ldltr sw360dp w360dp h615dp 480dpi nrml long port finger -keyb/v/h -nav/h s.6}
taskDescription: iconFilename=null label="null" color=ffadd44b
launchFailed=false launchCount=0 lastLaunchTime=-2m18s969ms
haveState=true icicle=Bundle[mParcelledData.dataSize=3876]
state=STOPPED stopped=true delayedResume=false finishing=false
keysPaused=false inHistory=true visible=false sleeping=false idle=true
fullscreen=true noDisplay=false immersive=false launchMode=0
frozenBeforeDestroy=false forceNewConfig=false
mActivityType=APPLICATION_ACTIVITY_TYPE
waitingVisible=false nowVisible=false lastVisibleTime=-2m18s47ms
Running activities (most recent first):
TaskRecord{3470ba7b #300 A=icom.package.example U=0 sz=3}
Run #2: ActivityRecord{3da3f636 u0 icom.package.example/.view.WebActivity t300}
Run #1: ActivityRecord{2017cfc8 u0 icom.package.example/.view.JobDetailsActivity t300}
Run #0: ActivityRecord{d9eeb4e u0 icom.package.example/.view.MainActivity t300}
mResumedActivity: ActivityRecord{3da3f636 u0 icom.package.example/.view.WebActivity t300}
mLastPausedActivity: ActivityRecord{2017cfc8 u0 icom.package.example/.view.JobDetailsActivity t300}
有3项跑步活动 当我按下后退按钮时,这就是堆栈:
Task id #300
* TaskRecord{3470ba7b #300 A=icom.package.example U=0 sz=1}
userId=0 effectiveUid=u0a199 mCallingUid=u0a199 mCallingPackage=icom.package.example
affinity=icom.package.example
intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=icom.package.example/.view.SplashScreenActivity}
realActivity=icom.package.example/.view.SplashScreenActivity
autoRemoveRecents=false isPersistable=true numFullscreen=1 taskType=0 mTaskToReturnTo=1
rootWasReset=false mNeverRelinquishIdentity=true mReuseTask=false
Activities=[ActivityRecord{d9eeb4e u0 icom.package.example/.view.MainActivity t300}]
askedCompatMode=false inRecents=true isAvailable=true
lastThumbnail=android.graphics.Bitmap@22f31098 lastThumbnailFile=/data/system/recent_images/300_task_thumbnail.png
hasBeenVisible=true firstActiveTime=1517840391154 lastActiveTime=1517840391154 (inactive for 4s)
* Hist #0: ActivityRecord{d9eeb4e u0 icom.package.example/.view.MainActivity t300}
packageName=icom.package.example processName=icom.package.example
launchedFromUid=10199 launchedFromPackage=icom.package.example userId=0
app=ProcessRecord{21ce55f9 17355:icom.package.example/u0a199}
Intent { flg=0x10008000 cmp=icom.package.example/.view.MainActivity (has extras) }
frontOfTask=true task=TaskRecord{3470ba7b #300 A=icom.package.example U=0 sz=1}
taskAffinity=icom.package.example
realActivity=icom.package.example/.view.MainActivity
baseDir=/data/app/icom.package.example-2/base.apk
dataDir=/data/data/icom.package.example
stateNotNeeded=false componentSpecified=true mActivityType=0
compat={480dpi} labelRes=0x7f0d001f icon=0x7f0c0000 theme=0x7f0e0007
config={0 1.0 222mcc99mnc it_IT ldltr sw360dp w360dp h615dp 480dpi nrml long port finger -keyb/v/h -nav/h s.6}
taskDescription: iconFilename=null label="null" color=ffadd44b
launchFailed=false launchCount=0 lastLaunchTime=-2m54s257ms
haveState=false icicle=null
state=RESUMED stopped=false delayedResume=false finishing=false
keysPaused=false inHistory=true visible=true sleeping=false idle=true
fullscreen=true noDisplay=false immersive=false launchMode=0
frozenBeforeDestroy=false forceNewConfig=false
mActivityType=APPLICATION_ACTIVITY_TYPE
waitingVisible=false nowVisible=true lastVisibleTime=-4s367ms
Running activities (most recent first):
TaskRecord{3470ba7b #300 A=icom.package.example U=0 sz=1}
Run #0: ActivityRecord{d9eeb4e u0 icom.package.example/.view.MainActivity t300}
mResumedActivity: ActivityRecord{d9eeb4e u0 icom.package.example/.view.MainActivity t300}
mLastPausedActivity: ActivityRecord{2017cfc8 u0 icom.package.example/.view.JobDetailsActivity t300 f}
正如你所看到的,只剩下一项活动了,我不知道为什么会这样。
答案 0 :(得分:0)
private void moveBack() {
//check for entry count
if (fragmentManager != null && fragmentManager.getBackStackEntryCount() > 1) {
fragmentManager.popBackStack();
} else {
finish();
}
}