我有一个简单的设置,可以启动拨号器以使用
ACTION_CALL
拨打电话
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_launch_dialer)
Log.d("TAG", "onCreate")
findViewById<Button>(R.id.btn_launch).setOnClickListener {
Log.d("TAG", "Launching Call")
val uri = Uri.parse("tel:3332223333")
val intent = Intent(Intent.ACTION_CALL, uri)
startActivity(intent)
}
}
override fun onResume() {
super.onResume()
Log.d("TAG", "onResume")
}
override fun onPause() {
super.onPause()
Log.d("TAG", "onPause")
}
我正在记录每个生命周期并看到奇怪的行为。一旦用户单击启动按钮,似乎会出现额外的
onPause
onResume
。
单击上面的启动按钮时,我得到以下日志输出。
Launching Call
onPause
onResume <-- This is unexpected
onPause
onStop
我无法弄清楚为什么生命周期在最初的
onResume
之后转换回 onPause
。有什么办法可以防止这种情况发生吗?
其他背景: 我正在尝试在
onPause
中做一些工作,但由于意外的 onResume
电话,它被重复了
返回应用程序时,您无法避免调用 onResume()。因为 Activity 生命周期正在处理此行为。我想,这个链接会对你有帮助