android Activity 被创建多次

在部分手机上,我的Activity被启动了两次。
但是这个Activity我设置了这些属性
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize"

AndroidManifest.xml中的application标签下面的第一个activity是SplashActivity,第二个是MainActivity。
其中SplashActivity就是开屏也之后展示广告的。
下面的日志是我整理出来的

info, 01-30 17:36:56.760, 27560, 27560, AD_DEMO, SplashActivity-------------onCreate
info, 01-30 17:36:56.790, 27560, 27560, AD_DEMO, SplashActivity-------------onResume------false
info, 01-30 17:36:57.277, 27560, 30045, AD_DEMO, SplashActivity-------------showSplahAd
info, 01-30 17:36:57.278, 27560, 30045, AD_DEMO, SplashActivity-------------fetchSplashAD
info, 01-30 17:36:57.729, 27560, 27560, AD_DEMO, SplashActivity-------------SplashADPresent
info, 01-30 17:36:57.755, 27560, 27560, AD_DEMO, SplashADTick 4974ms
info, 01-30 17:37:02.770, 27560, 27560, AD_DEMO, SplashADExposure
info, 01-30 17:37:02.770, 27560, 27560, AD_DEMO, SplashActivity-------------SplashADDismissed
info, 01-30 17:37:02.802, 27560, 27560, AD_DEMO, SplashActivity-------------onPause------true
info, 01-30 17:37:02.837, 27560, 27560, AD_DEMO, MainActivity-------------onResume
info, 01-30 17:37:03.070, 27560, 27560, AD_DEMO, SplashActivity-------------onDestroy

info, 01-30 17:37:03.295, 27560, 27560, AD_DEMO, MainActivity-------------onPause
info, 01-30 17:37:03.331, 27560, 27560, AD_DEMO, SplashActivity-------------onCreate
info, 01-30 17:37:03.347, 27560, 27560, AD_DEMO, SplashActivity-------------onResume------false
info, 01-30 17:37:03.843, 27560, 30404, AD_DEMO, SplashActivity-------------showSplahAd
info, 01-30 17:37:03.846, 27560, 30404, AD_DEMO, SplashActivity-------------fetchSplashAD
info, 01-30 17:37:04.174, 27560, 27560, AD_DEMO, SplashActivity-------------SplashADPresent
info, 01-30 17:37:04.238, 27560, 27560, AD_DEMO, SplashADTick 4936ms
info, 01-30 17:37:09.255, 27560, 27560, AD_DEMO, SplashADExposure
info, 01-30 17:37:09.255, 27560, 27560, AD_DEMO, SplashActivity-------------SplashADDismissed
info, 01-30 17:37:09.270, 27560, 27560, AD_DEMO, SplashActivity-------------onPause------true
info, 01-30 17:37:09.321, 27560, 27560, AD_DEMO, MainActivity-------------onResume
info, 01-30 17:37:09.555, 27560, 27560, AD_DEMO, SplashActivity-------------onDestroy

2个回答

试试设置这个属性android:launchMode="singleTask"

看log你应该进入MainActivity后重新启动了SplashActivit,是不是异步下载广告之后又重新弹出SplashActivy,

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐