How can I display a dialog from the receiver for Android broadcasting?

Ideally, I do not want to start work to do this. When the Wi-Fi connection is lost, my application needs to close, because this is a fatal error for us. I want to show an error message and click Ok, and then exit the application. What is the best way to do this?

Thanks!

+3
source share
1 answer

AFAIK, only actions can display dialogs. If yes, and if your BroadcastReceiver registered through an action through registerReceiver() , you are configured - just use this activity. If, however, your BroadcastReceiver registered in the manifest, I think you will have no choice but to do something else.

For example, you can send an ordered broadcast of Intent . In your current action - if any - BroadcastReceiver will take precedence for this Intent , and then a dialog may appear when it receives the broadcast. If, however, none of your actions are displayed on the screen, you could register a low priority BroadcastReceiver with confirmed BroadcastReceiver manifests if you want to display Notification or something else. Here is a blog post that covers a bit more about this template.

+7
source

Source: https://habr.com/ru/post/1369480/


All Articles