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(); } };