我需要显示并维护一个对话框,该对话框在特定时间段(例如30 s)后在Android应用程序上消失。但是我遇到了一些困难:
如何记录主机(始终处于活动状态)或正在结束时的显示时间?
如果需要,其他主机恢复后如何重新显示对话框?
我通过以下代码尝试了,但是没用
// 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中的全局对话框?感谢您的收看和回答:)
resumeToShow()并检查时间,并根据需要显示对话框