我是服务新手。我已经使用 AlaramManager 启动了服务。它可以正常工作,但是当我尝试停止服务时,它不会停止服务。
启动服务的方法
Calendar cur_cal = Calendar.getInstance();
cur_cal.setTimeInMillis(System.currentTimeMillis());
Intent intent = new Intent(XoroActivity.this, XorService.class);
pintent = PendingIntent.getService(XoroActivity.this,
0, intent, 0);
alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
mStarted = true;
if (mB_IntervalStr.equals("1 minute")) {
alarm.setRepeating(AlarmManager.RTC_WAKEUP,
cur_cal.getTimeInMillis(), 1 * 60 * 1000, pintent);
} else if (mB_IntervalStr.equals("2 minutes")) {
alarm.setRepeating(AlarmManager.RTC_WAKEUP,
cur_cal.getTimeInMillis(), 2 * 60 * 1000, pintent);
} else if (mB_IntervalStr.equals("5 minutes")) {
alarm.setRepeating(AlarmManager.RTC_WAKEUP,
cur_cal.getTimeInMillis(), 5 * 60 * 1000, pintent);
} else if (mB_IntervalStr.equals("10 minutes")) {
alarm.setRepeating(AlarmManager.RTC_WAKEUP,
cur_cal.getTimeInMillis(), 10 * 60 * 1000, pintent);
} else if (mB_IntervalStr.equals("30 minutes")) {
alarm.setRepeating(AlarmManager.RTC_WAKEUP,
cur_cal.getTimeInMillis(), 30 * 60 * 1000, pintent);
} else if (mB_IntervalStr.equals("60 minutes")) {
alarm.setRepeating(AlarmManager.RTC_WAKEUP,
cur_cal.getTimeInMillis(), 60 * 60 * 1000, pintent);
}
停止服务的方法
Intent i = new Intent();
i.setClassName("com.teks.xormobile", "com.teks.xormobile.XorService");
stopService(i);
alarm.cancel(pintent);
这没用。请给我一个如何停止服务的解决方案....