在Android的特定时间呼叫服务

编程入门 行业动态 更新时间:2024-10-20 08:23:07
本文介绍了在Android的特定时间呼叫服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在后台服务运行。结果我想打电话给在特定的时间间隔这项服务。结果如果用户提供值10,20,30比服务应10分钟,20分钟和30分钟后接受性调用。

I have service run in background. I want to call this service at specific interval. if user provide values 10, 20, 30 than service should call after 10 min,20 min and 30 min receptively.

我怎样才能做到上述的事情吗?

How can I do above thing?

推荐答案

AlarmManager 将帮助您:)

AlarmManager will help you :)

它允许您设置一个时间表规定的时间范围内启动应用程序的组件

It allows you to set up a schedule to launch your application's components during the specified time range

要实例化一个 AlarmManager 它实例化后会发挥作用的特定时期, setRepeating配置()方法和周期参数添加到 SystemClock.elapsedRealime():

To instantiate an AlarmManager that will go into play at the specific period after it's instantiating, configure it with setRepeating() method and PERIOD parameter added to SystemClock.elapsedRealime():

AlarmManager mgr = (AlarmManager)getSystemService(ALARM_SERVICE); mgr.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + PERIOD, PERIOD, pi); // Here PERIOD is a value specified by you as PendingIntent object

更多推荐

在Android的特定时间呼叫服务

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

发布评论

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

>www.elefans.com

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