So I'm running into an error with my BroadcastREceiver...the receiver is running and detecting the change in network..as soon as I add the visiblity it cans out...
Where it is canning out is at the change of visibility of the warning_message in the
val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager
val networkInfo = connectivityManager.activeNetworkInfo
if (networkInfo != null && networkInfo.detailedState == NetworkInfo.DetailedState.CONNECTED) {
Log.d("Network Connected","NC is connected")
MainActivity().warning_message.visibility = View.INVISIBLE
MainActivity().isConnected = true
} else if (networkInfo != null) {
val state = networkInfo.detailedState
Log.d("NetworkReceiver", state.name)
} else {
MainActivity().warning_message.visibility = View.VISIBLE
MainActivity().isConnected = false
Log.d("Network Connected","NC")
}
}
The warning message is just a:
<FrameLayout
android:id="@+id/warning_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/top_toolbar">
in the Main Activity layout.
The error I receive is: Process: com.example.user.appname, PID: 19972
java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x4000010 (has extras) } in com.example.user.appname.ConnectionReceiver@531d646
There is no specific error message as to why.