Ideally, I do not want to start an activity to do this. When the WiFi connection is lost, my app needs to close because this is a fatal error for us. I want to display an error message and have the user press an Ok button and then exit the app. What is the best way to go about this?
Thanks!
AFAIK, only activities can display dialogs. If so, and if your
BroadcastReceiveris registered by an activity viaregisterReceiver(), you’re set — just use that activity. If, however, yourBroadcastReceiveris registered in the manifest, I think you will have no choice but to do something else.For example, you could send an ordered broadcast
Intent. Your currently-running activity — if any — would have a high-priorityBroadcastReceiverfor thatIntent, then can pop a dialog when it receives the broadcast. If, however, none of your activities are on screen, you could have a manifest-registered low-priorityBroadcastReceiverpick up the broadcast, if you wanted to display aNotificationor something. Here is a blog post that covers a bit more about this pattern.