我正在使用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);