0
我是新來的服務。我已經通過使用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);
它不工作。請給我一個解決方案,以如何停止服務....
我已經嘗試過stopSelf()方法,但它不工作.... –
好吧,知道這很好這是工作me.My服務是停止。我只是創建警報對象和待定的意圖對象pintent = PendingIntent.getService(XoroActivity.this, 0,i,0); alarm =(AlarmManager)getSystemService(Context.ALARM_SERVICE); –