Notification failed to start broadcast

After the phone is turned on, the background broadcasts are flying all over the sky. The broadcast started by clicking on the Notification of your own application may not respond for a long time. At this time, add FLAG_RECEIVER_FOREGROUND. Note that this flag was introduced in API 16.

Example:
Intent intent = new Intent(context, XXXReceiver.class);
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
            intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
        }
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
...


Note the doc of 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.
     */
    public static final int FLAG_RECEIVER_FOREGROUND = 0x10000000;

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326818239&siteId=291194637