[英]Android Activity LifeCycle - when 'onPause' is called?
I am an Android app developer.我是 Android 应用程序开发人员。
I thought I know the life cycle of the activity.我以为我知道活动的生命周期。
But... I am confused now.但是……我现在很困惑。
As per the official docs: https://developer.android.com/guide/components/activities/activity-lifecycle.html#onpause根据官方文档: https://developer.android.com/guide/components/activities/activity-lifecycle.html#onpause
'onPause' is called when partially invisible.部分不可见时调用“onPause”。
A new, semi-transparent activity (such as a dialog) opens.
一个新的、半透明的活动(例如对话框)打开。 As long as the activity is still partially visible but not in focus, it remains paused.
只要活动仍然部分可见但不在焦点上,它就会保持暂停状态。
So I have thought that if a dialog is opened, then the activity is paused.所以我认为如果打开一个对话框,那么活动就会暂停。
I made some sample code to prove this.我做了一些示例代码来证明这一点。
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btn.setOnClickListener {
// 1. AlertDialog
// AlertDialog.Builder(this)
// .setTitle("TEST")
// .show()
// 2. DialogFragment
// val dialog = TestFragment()
// supportFragmentManager.beginTransaction().add(dialog, "").commit()
}
}
override fun onPause() {
super.onPause()
Log.d("TEST", "[LifeCycle] onPause")
}
When I clicked the "btn", Dialog/DialogFragment is opened.当我单击“btn”时,会打开 Dialog/DialogFragment。 But 'onPause' log was not printed out.
但是“onPause”日志没有打印出来。
I am confused...我很困惑...
Does the official document incorrect?官方文档有误吗?
It also states that它还指出
The system calls this method as the first indication that the user is leaving your activity [...] it indicates that the activity is no longer in the foreground
系统调用此方法作为用户离开您的活动的第一个指示 [...] 它表明活动不再在前台
A dialog within your own activity will not pause it.您自己的活动中的对话框不会暂停它。 Only a new activity containing the dialog would pause the first one.
只有包含对话框的新活动才会暂停第一个活动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.