0

我正在启动一项服务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);
4

0 回答 0