我想设置我第一次进入主屏幕时仅出现一次的bottomsheetDialog
。
当前,在onStart
函数中创建了一个对话框,但是如果您这样做,即使从另一个 Activity 切换到主 Activity ,该对话框也会出现。
检查我下面的代码:
override fun onStart() {
super.onStart()
val notifyBottomDialogFragment: BottomNotifyFragment = BottomNotifyFragment {
when (it)
{
}
}
notifyBottomDialogFragment.show(supportFragmentManager, notifyBottomDialogFragment.tag)
notifyBottomDialogFragment.isCancelable = false
}
最佳答案
也许尝试在OnCreate
函数中显示一个对话框。并保存 bool(boolean) 值以检查是否是首次创建“ Activity ”(例如,用户旋转手机或进入分屏模式):
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity()
{
companion object
{
var firstRun = true
}
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Log.d("MyTag", "Create")
if (firstRun)
{
Log.d("MyTag", "Main screen showed for the first time")
firstRun = false;
}
else
{
Log.d("MyTag", "Main screen NOT showed for the first time")
}
}
}
关于android - 如果仅在Kotlin中首次执行主要 Activity 时才出现对话框,该怎么办?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63858904/