我的警报管理器无法在后台运行

编程入门 行业动态 更新时间:2024-10-27 22:21:06
本文介绍了我的警报管理器无法在后台运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我为应用程序警报管理器做了准备.我需要每小时运行一次,并检查数据是否已更改.

I prepared for my application alarm manager. I need run this every hour and check if data is changed.

我已将警报管理器设置如下:

Calendar cal = Calendar.getInstance(); cal.add(Calendar.HOUR, 1); android.app.AlarmManager alarmMgr = (android.app.AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE); Intent intent = new Intent(mContext, AnalysisNotificationReceiver.class); PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, ALARM_ID, intent, 0); if (Calendar.getInstance().after(cal)) { cal.add(Calendar.DAY_OF_MONTH, 1); } alarmMgr.setRepeating(android.app.AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 60 * 60 * 1000, pendingIntent);

它应该每60分钟工作一次,我不确定我是否设置正确,但是在应用关闭时不起作用.

It's should work in every 60 minutes I'm not sure if I set correctly but doesn't work when app close.

有人知道吗? 谢谢

推荐答案

您可以尝试一下,它对我有用

You can try this, it worked for me

AlarmManager alarmManager= (AlarmManager) getSystemService(Context.ALARM_SERVICE); Intent scheduleServiceExecuterIntent = new Intent(this, ScheduledServiceExecuter.class); scheduleServiceExecuterIntent.putExtra("state", "Main"); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, request_code, intent, 0); alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, time, AlarmManager.INTERVAL_HOUR, pendingIntent);

更多推荐

我的警报管理器无法在后台运行

本文发布于:2023-11-27 05:45:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636831.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管理器   警报   后台

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!