Broadcasts are delayed

前端 未结 1 1160
孤街浪徒
孤街浪徒 2021-02-20 05:19

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)

相关标签:
1条回答
  • 2021-02-20 05:56

    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

    0 讨论(0)
提交回复
热议问题