我在使用PlayerActivity时遇到以下情况。
当我按播放器上的后退按钮(播放时)时,PlayerActivity会依次调用onPause()
,然后依次调用onStop()
和最后onDestroy()
。
但是,当我使PlayerActivity进入暂停状态(例如启动语音搜索),然后允许它进入恢复状态(通过退出语音搜索),然后按返回按钮不会调用onStop()
和onDestroy()
方法-仅调用onPause()
。
所以我的问题是-即使活动不再可见,为什么没有调用onStop()
吗?
这些是有助于可视化此情况的日志:
Normal activity lifecycle for player:
01-10 18:44:58.799 27817-27817/com.google.android.exoplayer2.demo D/PlayerActivity: onCreate()
01-10 18:44:58.916 27817-27817/com.google.android.exoplayer2.demo D/PlayerActivity: onStart()
01-10 18:44:58.917 27817-27817/com.google.android.exoplayer2.demo D/PlayerActivity: onResume()
Back button pressed on PlayerActivity:
01-10 18:45:14.768 27817-27817/com.google.android.exoplayer2.demo D/PlayerActivity: onPause()
01-10 18:45:14.968 27817-27817/com.google.android.exoplayer2.demo D/PlayerActivity: onStop()
01-10 18:45:14.968 27817-27817/com.google.android.exoplayer2.demo D/PlayerActivity: onDestroy()
PlayerActivity destroyed.
Player initiated second time:
01-10 18:45:21.874 27817-27817/com.google.android.exoplayer2.demo D/PlayerActivity: onCreate()
01-10 18:45:21.899 27817-27817/com.google.android.exoplayer2.demo D/PlayerActivity: onStart()
01-10 18:45:21.899 27817-27817/com.google.android.exoplayer2.demo D/PlayerActivity: onResume()
Voice control is initiated on TV remote - causes Activity to PAUSE state
01-10 18:45:27.180 27817-27817/com.google.android.exoplayer2.demo D/PlayerActivity: onPause()
Voice control finished causing Activity to RESUMED state
01-10 18:45:29.414 27817-27817/com.google.android.exoplayer2.demo D/PlayerActivity: onResume()
Back button pressed on PlayerActivity
01-10 18:45:32.160 27817-27817/com.google.android.exoplayer2.demo D/PlayerActivity: onPause()
// This is it - Activity’s onStop() and onDestroy() not called