停止使用AlarmManager启动的服务

时间:2013-05-12 11:43:53

标签: android android-alarms

我正在使用AlarmManager启动服务,该服务在5分钟后唤醒并执行某些任务,但我无法停止服务。我怎么能这样做?

启动服务的代码:

Intent myIntent = new Intent(MainActivity.this, SendDataService.class);  
pendingIntent = PendingIntent.getService(MainActivity.this, 0, myIntent, 0);

AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);  
Calendar calendar = Calendar.getInstance();  
calendar.setTimeInMillis(System.currentTimeMillis());

// Wake up after 5 minutes
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000*60*5, pendingIntent);

0 个答案:

没有答案