question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setBroadcast(true) hangs on Android

See original GitHub issue

In order to send broadcast messages we need to call setBroadcast() first. However this method hangs and never returns!

protected void doInBackgroundGuarded(Void... params) {
	UdpSocketClient client = findClient(cId, callback);
	if (client == null) {
		return;
	}

	try {
		client.setBroadcast(flag);
		// **** we never get there!

		callback.invoke();
	} catch (SocketException e) {
		callback.invoke(UdpErrorUtil.getError(null, e.getMessage()));
	}
}

I tested in Android emulator and with a Samsung Galaxy S8. Both running on Android API 28. Any ideas what is going on here?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
shynstcommented, Jun 18, 2021

@nishmeht7: I did fix it 2 years ago (works very well in production code):

It seems we must not call setBroadcast() after the receiving thread was started, since this will result in a deadlock. Therefore I removed automatic start of receive on bind and introduced a new method startReveiving().

See details in my commit above.

0reactions
nishmeht7commented, Jun 23, 2021

@shynst Thank you so much, you’re a life saver!

Read more comments on GitHub >

github_iconTop Results From Across the Web

setBroadcast(true) not working on Android #96 - GitHub
When calling socket.setBroadcast(true) on Android after binding the socket, it makes whole the process hang forever. This method works on iOS.
Read more >
Why BROADCAST receiver registration causing error. My app ...
You absolutely need to keep android:exported="true" , because this enables your broadcast receiver to listen to events triggered outside ...
Read more >
Broadcasts overview | Android Developers
When a broadcast is sent, the system automatically routes broadcasts to apps ... other apps, even other apps that you own, set android:exported...
Read more >
Android 8+ crash at boot_completed - MSDN - Microsoft
Below, you can see my broadcast receiver. [BroadcastReceiver( Name = "com.parroinfo.SERVICE_STARTUP", Enabled = true, Exported = true, ...
Read more >
Get help during an emergency with your Android phone
Some of these steps work only on Android 12 and up. Learn how to check your Android version. ... Control emergency broadcast notifications....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found