NotificationService system_server W Blocking custom toast from package com.example.androidtest due to package not in the foreground at time the toast was posted Blockquote
When I try to show a custom Toast right after request for permission On Android >= 11, I got the above warning and the custom Toast won't show
private val requestPermissionLauncher = registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted: Boolean ->
}
override fun onCreate(savedInstanceState: Bundle?) {
...
buttonCamera.setOnClickListener {
requestPermissionLauncher.launch(android.Manifest.permission.CAMERA)
makeCommonToast("ABc").show()
}
}
private fun makeCustomToast(message: CharSequence): Toast {
return Toast.makeText(context, "", Toast.LENGTH_LONG).apply {
val rootView = LayoutInflater.from(context).inflate(R.layout.my_custom_toast, null)
view = rootView
val textView = rootView.findViewById<TextView>(R.id.text_message)
textView.text = message
}
}
I thought the app still in foreground but the Toast won't showing