Остановить службу в деятельности
Я использую следующий код, чтобы остановить мой сервис
Intent intent = new Intent(MainActivity.this, UsageRecorderService.class);
stopService(intent);
И это мой сервис, который работает бесконечно
public class UsageRecorderService extends IntentService {
public UsageRecorderService() {
super("UsageRecorder");
}
@Override
protected void onHandleIntent(Intent intent) {
while (true) {
UsageRecorder.recordUsages(this, false);
SystemClock.sleep(10000);
}
}
}
Почему не останавливается мой сервис?