android intent.actiontimetick,收不到ACTION_TIME_TICK的广播

在Android服务中注册ACTION_TIME_TICK广播时,遇到广播未触发的问题。问题根源在于`stopSelf()`方法导致通知栏通知未清除,而非广播本身。在`onStartCommand()`中,创建并显示了通知,同时注册了ACTION_TIME_TICK的广播接收器。当调用`alarm = getNextAlarm();`时,服务被意外停止,导致通知无法清除,误导认为广播接收器未工作。解决方案是正确处理服务的生命周期与通知管理。
摘要由CSDN通过智能技术生成

已解决……

问题不在于ACTION_TIME_TICK,而是我中途调用的方法会在特定情况下stopself

我本以为在service中加的那个notification会随着stopself消失,结果它没消失……于是我以为是广播出了问题……

以下是原题……

——————————————————————————————————————————————————————————————————————

我看google是这么说的

Broadcast Action: The current time has changed. Sent every minute. You

cannot receive this through components declared in manifests, only by

explicitly registering for it with Context.registerReceiver().

于是我的代码:

public class AlarmService extends Service {

......

@Override

public int onStartCommand(Intent intent, int flags, int startId) {

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

builder.setSmallIcon(R.drawable.alarm_notify);

NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值