Can i use AlarmManager with LocalBroadcastManager on android?

北城以北 提交于 2019-12-01 03:07:32

No, it is not possible, because LocalBroadcastManager is only for your own process, and AlarmManager's backend runs in a different process. That is why there is no way to create a PendingIntent that works with LocalBroadcastManager.

But you could register a BroadcastReceiver which basically converts the "Global" Broadcast into a LocalBroadcast:

public class AutoUpdateBroadcastReceiver extends BroadcastReceiver {

  private static final String TAG = AutoUpdateBroadcastReceiver.class.getSimpleName();

  @Override
  public void onReceive(Context context, Intent intent) {
    Log.d(TAG, ".onReceive");
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(context);
    lbm.sendBroadcast(intent);
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!