I\'ve got an app that responds to an Alert - and I really need to show an alert with a password entry before going on to the next screen; the trouble is I don\'t seem to be able
You can't open Dialog from Receivers because it need ActivityContext
Alternate way You can open Acivity like dialog. Full example :
MyReceiver.kt
class AlarmReceiver : BroadcastReceiver {
private val REMINDER_BUNDLE = "MyReminderBundle"
override fun onReceive(context: Context?, intent: Intent?) {
val mIntent = Intent(context, DialogActivity::class.java)
mIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
context?.startActivity(mIntent)
}
}
AndroidManife.xml
DialogActivity.kt
class DialogActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_dialog)
this.setFinishOnTouchOutside(true)
// create custom view of your dialog in activity_dialog
// or you can direct call alert dialog
}
}