Created
August 20, 2019 04:59
-
-
Save firecatmusic/beee342e9b7619f83c4f284ff79ba18f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var connectionReceiver: ConnectionReceiver? = null | |
override fun onStart() { | |
super.onStart() | |
connectionReceiver = ConnectionReceiver() | |
registerReceiver(connectionReceiver, IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION)) | |
} | |
override fun onStop() { | |
try { | |
unregisterReceiver(connectionReceiver) | |
} catch (e: IllegalStateException) { | |
e.printStackTrace() | |
} | |
super.onStop() | |
} | |
inner class ConnectionReceiver : BroadcastReceiver() { | |
override fun onReceive(context: Context?, intent: Intent?) { | |
val isOnline = NetworkUtil.getConnectivityStatusString(this@Activity) | |
if (!isOnline) showDialogNoInternet(this@Activity) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment