zoukankan      html  css  js  c++  java
  • android 使用AlarmManager定时启动service

        private static AlarmManager am;
        private static PendingIntent pendingIntent;
    
        /**
         * 使用 AlarmManager 来 定时启动服务
         */
        public static void startPendingIntent(Context context) {
    
            am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    
            Intent intent = new Intent(context, MyService.class);//启动示例Service
    
            pendingIntent = PendingIntent.getService(context, 0, intent, 0);
    
            long interval = DateUtils.MINUTE_IN_MILLIS * 30;// 30分钟一次
    
            long firstWake = System.currentTimeMillis() + interval;
    
            am.setRepeating(AlarmManager.RTC, firstWake, interval, pendingIntent);
    
        }
    
        public static void stopPendingIntent() {
    
            if (pendingIntent != null) {
    
                pendingIntent.cancel();
    
            }
        };
  • 相关阅读:
    php函数、php定义数组和数组遍历
    php语句
    php基础
    phpcms 标题设置
    上传头像预览
    简单的轮播样式
    ajax 小练习
    生成地图
    php注释规范
    thinkphp 实现分页
  • 原文地址:https://www.cnblogs.com/code4app/p/3688115.html
Copyright © 2011-2022 走看看