【Android】LocalBroadcastManager 注册的广播对 PendingIntent 无效

【问题】

LocalBroadcastManager 注册的广播,不可用于 PendingIntent.getBroadcast();(我打算打算通过广播和 AlarmManager 写一个定时器,却发现一直收不到广播;)

【分析】
  1. LocalBroadcastManager 注册的广播在自己的进程中有效,而 AlarmManager 是系统级别的服务;
  2. A pending intent is a token that you give to another application (e.g., notification manager, alarm manager or other 3rd party applications), which allows this other application to use the permissions of your application to execute a predefined piece of code.
【解决方案】

在需要用到 PendingIntent 的地方,使用全局的动态广播或静态广播;

【参考资料】
  1. Can i use AlarmManager with LocalBroadcastManager on android?
  2. Android BroadcastReceiver - Tutorial
  3. Global broadcast or local broadcast with PendingIntent
  4. Can i use AlarmManager with LocalBroadcastManager on android?

你可能感兴趣的:(【Android】LocalBroadcastManager 注册的广播对 PendingIntent 无效)