如何使用报警管理计划任务

编程入门 行业动态 更新时间:2024-10-11 05:20:47
本文介绍了如何使用报警管理计划任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是新来的Andr​​oid。我在一个应用程序的工作中,我需要计划将在未来被执行的任务。

I am new to Android. I am working on an App in which I need to schedule a task that will be performed in future.

我看了一下AlarmManager和了解,以我们能够做到这一点使用AlarmManager。

I have read about AlarmManager and get to know to that we can accomplish this using AlarmManager.

谁能告诉我一些教程或任何来源在哪里可以得到的东西。

Can anyone please tell me about some tutorial or any source where can I get the things.

推荐答案

内容摘自博客Scheduling任务在Android中使用报警管理器

public void scheduleAlarm(View v) { // The time at which the alarm will be scheduled. Here the alarm is scheduled for 1 day from the current time. // We fetch the current time in milliseconds and add 1 day's time // i.e. 24*60*60*1000 = 86,400,000 milliseconds in a day. Long time = new GregorianCalendar().getTimeInMillis()+24*60*60*1000; // Create an Intent and set the class that will execute when the Alarm triggers. Here we have // specified AlarmReceiver in the Intent. The onReceive() method of this class will execute when the broadcast from your alarm is received. Intent intentAlarm = new Intent(this, AlarmReceiver.class); // Get the Alarm Service. AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // Set the alarm for a particular time. alarmManager.set(AlarmManager.RTC_WAKEUP, time, PendingIntent.getBroadcast(this, 1, intentAlarm, PendingIntent.FLAG_UPDATE_CURRENT)); Toast.makeText(this, "Alarm Scheduled for Tommrrow", Toast.LENGTH_LONG).show(); }

AlarmReceiver类

public class AlarmReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { // Your code to execute when the alarm triggers // and the broadcast is received. } }

更多推荐

如何使用报警管理计划任务

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

发布评论

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

>www.elefans.com

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