I have a simple broadcast receiver set to receive system intents informing my application of a change in network status. The idea is to either show a dialog telling the user they have left the WiFI network on which the app runs or have lost their connection altogether.
public class NetworkChangedReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION)){
boolean connected = intent.getBooleanExtra(WifiManager.EXTRA_SUPPLICANT_CONNECTED,false);
if(!connected){
//connection off
Log.w("Network Changed","SUPPLICATION_CONNECTION_CHANGE_ACTION");
}
}else if(intent.getAction().equals(WifiManager.NETWORK_STATE_CHANGED_ACTION)){
NetworkInfo info = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
if(info.isConnected()){
//connection on or WIFI changed
Log.w("Network Changed","NETWORK_STATE_CHANGED_ACTION");
}
}
}
}
Is it possible for me to even display a dialog in this manner? I have no way of knowing where the user is in the application, an unknown state for when the broadcast is received. My other option is to jump the user back to my Login activity using an intent with a string and boolean extra to test. Is it bad programming practice to do so?
In that case when you receive the Broadcast You should consider showing notification in notification bar
When User will click on notification you can navigate them to Login Activity.