Ensure receiver unregistered synchronously in onDestroy

This commit is contained in:
Mygod
2019-07-31 10:03:27 +08:00
parent 1f2ccf83b0
commit e55aa17399
3 changed files with 17 additions and 20 deletions

View File

@@ -19,6 +19,7 @@ import androidx.databinding.BindingAdapter
import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.room.macToString
import be.mygod.vpnhotspot.widget.SmartSnackbar
import java.lang.IllegalArgumentException
import java.net.InetAddress
import java.net.NetworkInterface
import java.net.SocketException
@@ -35,6 +36,12 @@ fun Long.toPluralInt(): Int {
return (this % 1000000000).toInt() + 1000000000
}
fun Context.ensureReceiverUnregistered(receiver: BroadcastReceiver) {
try {
unregisterReceiver(receiver)
} catch (_: IllegalArgumentException) { }
}
@SuppressLint("Recycle")
fun <T> useParcel(block: (Parcel) -> T) = Parcel.obtain().run {
try {