我需要在 Android 应用程序上显示并维护一个在一定时间(例如:30 秒)后消失的对话框。但是我遇到了一些困难:</p>
如何记录主机(始终是活动)被破坏或正在完成的显示时间?
如果需要,当其他主机恢复时如何重新显示对话框?
我用下面的代码试了一下,还是不行
// dialog that I want to show.
class BusinessBroadcastDialog(activity: Activity, private val tag: String) : AlertDialog(activity)
object GlobalShowableManager {
fun show(duration: Int) {
// ActivityRecorder.get() will return the activity which is on the top of task.
val activity = ActivityRecorder.get()
if (activity?.isActivityExist() == true) {
val tag = "${activity.javaClass.simpleName}#BusinessBroadcastDialog#$duration"
val dialog = BusinessBroadcastDialog(activity, tag).apply {
ownerActivity = activity
}
dialog.show()
} else {
Log.i(TAG, "no exist activity to show global dialog, break.")
}
}
fun resumeToShow() {
// will be called when other host resumed.
// get last BusinessBroadcastDialog showing time mark it as t.
// if t >= duration then do nothing,
// else let t = t - duration and show dialog. dialog will disappear after t seconds.
}
}
有没有(更好的)方式在android中显示全局对话框?感谢您的观看和回答:)