如果我的应用程序没有运行,AlarmManager 会工作吗? [英] Will AlarmManager work if my application is not running?

查看:39
本文介绍了如果我的应用程序没有运行,AlarmManager 会工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我正在与我的应用程序交互(使用),我有一个警报可以正常工作,但如果我将它设置为第二天而不与我的应用程序交互,它就不起作用.因此我怀疑这是因为我的应用程序过程那时没有运行.

I have an alarm that works fine if i am interacting(using) with my application but it dose not works if I set it for next day and not interacting with my app.Therefore I am getting doubt is this because my application process is not running at that time.

这是我在做什么

Calendar calSet = Calendar.getInstance();
calSet.set(Calendar.HOUR_OF_DAY, selectedhour);
calSet.set(Calendar.MINUTE, selectedminute);
calSet.set(Calendar.YEAR, year);
calSet.set(Calendar.MONTH, monthOfYear);
calSet.set(Calendar.DATE, dayOfMonth);
alarm = new Intent(ActivityA.this, Service.class);
pendingIntent = PendingIntent.getService(getApplicationContext(), i++,alarm, 1);
alarmanager.set(AlarmManager.RTC_WAKEUP, calSet.getTimeInMillis(),pendingIntent);

推荐答案

来自 报警管理器

AlarmManager 提供对系统警报服务的访问.这些允许您安排您的应用程序在未来的某个时间运行.当警报响起时,系统会广播为其注册的 Intent ,如果目标应用程序尚未运行,则会自动启动它.注册的闹钟在设备处于睡眠状态时会保留(如果设备在此期间关闭,可以选择唤醒设备),但如果关闭并重新启动,则会清除.

简单来说,它会一直工作到您的设备重新启动.

In simple way, it will work until your device has been rebooted.

您可以阅读重启后的Android AlarmManager,其中@CommonsWare 已获得他的链接示例应用程序即使在设备重新启动后仍然存在警报.

You can read Android AlarmManager after reboot where @CommonsWare has been given a link of his sample application which persists Alarm even after device reboot.

请忽略以下部分,它似乎无效.我以后会删除

Please ignore below section, it seems not valid. I will remove in future

您可以在 How to create一个持久的AlarmManager,以及如何在应用被杀后保存Alarm? 可以让您了解如何处理此类问题(如果应用程序被终止,则保持警报).

You can read more about application kill at How to create a persistent AlarmManager, and How to save Alarm after app killing? can give you the idea about how to handle such issue (to persist alarm if application has been killed).

这篇关于如果我的应用程序没有运行,AlarmManager 会工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆