我曾经认为当Activity A被另一个全屏的Activity B所取代时,A的onStop()
回调将被调用。
这也反映在文档中:
活动的可见生命周期发生在调用onStart()和调用onStop()之间。在此期间,用户可以在屏幕上看到活动并与其交互。例如,当启动新活动并且旧活动不再可见时,会调用onStop()。
然而,现在我观察到了不同的行为(在Lollipop和Marshmallow上进行了测试)。
我从HomeActivity启动AuthenticationActivity,尽管AuthenticationActivity是一个全屏活动,但HomeActivity并没有停止。
这些活动在清单中的声明:
<activity
android:name=".screens.home.activities.HomeActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".screens.authentication.activities.AuthenticationActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:windowSoftInputMode="adjustResize"
android:theme="@style/AppTheme.Transparent"/>
当活动切换时,我在logcat中观察到以下内容:
11-28 10:16:31.443 15183-15183/somepackage I/LOG:: LifeCycle : activity (somepackage.screens.home.activities.HomeActivity@3561e8e1) paused
11-28 10:16:31.583 15183-15183/somepackage I/LOG:: LifeCycle : activity (somepackage.screens.authentication.activities.AuthenticationActivity@2bbdb20f) created
11-28 10:16:31.753 15183-15183/somepackage D/Activity: performCreate Call secproduct feature valuefalse
11-28 10:16:31.753 15183-15183/somepackage D/Activity: performCreate Call debug elastic valuetrue
11-28 10:16:31.753 15183-15183/somepackage D/AuthenticationActivity: onStart()
11-28 10:16:31.753 15183-15183/somepackage I/LOG:: LifeCycle : activity (somepackage.screens.authentication.activities.AuthenticationActivity@2bbdb20f) started
11-28 10:16:31.993 15183-15183/somepackage D/AuthenticationActivity: onResume()
11-28 10:16:31.993 15183-15183/somepackage I/LOG:: LifeCycle : activity (somepackage.screens.authentication.activities.AuthenticationActivity@2bbdb20f) resumed
11-28 10:16:32.213 15183-15183/somepackage I/Timeline: Timeline: Activity_idle id: android.os.BinderProxy@266569db time:354918367
11-28 10:16:32.613 15183-15183/somepackage I/LOG:: LifeCycle : activity (somepackage.screens.home.activities.HomeActivity@3561e8e1) saveInstanceState
11-28 10:16:32.633 15183-15183/somepackage V/ActivityThread: updateVisibility : ActivityRecord{2bcd65fd token=android.os.BinderProxy@86da390 {somepackage/somepackage.screens.home.activities.HomeActivity}} show : true
发生了什么事情?