We use broadcasts to communicate state changes between a remote services and our UI. Doing this, we discovered a very strange behaviour: Sometimes (I can not find any clues why)
After searching for a answer for hours, I found the? solution after posting this.
It seems like that adding the FLAG_RECEIVER_FOREGROUND
flag to the intent completly removes this delay. Would be still nice to know why this happens and if this is a good "fix" or if I destroy something else with this.
This does the trick:
intent.setFlags(FLAG_RECEIVER_FOREGROUND);
If set, when sending a broadcast the recipient is allowed to run at foreground priority, with a shorter timeout interval. During normal broadcasts the receivers are not automatically hoisted out of the background priority class.
Source: https://developer.android.com/reference/android/content/Intent.html#FLAG_RECEIVER_FOREGROUND