2014-03-31 2 views
0

알람 시계 앱을 만들고 있습니다. 인 텐트를 사용하여 서비스를 시작합니다.동일한 서비스의 여러 인스턴스에서 서비스 중지

public void Start(View view) { 
    hr = timePick.getCurrentHour(); 
    min = timePick.getCurrentMinute(); 
    service = new Intent(this,MyService.class); 
    Bundle bundle = new Bundle(); 
    bundle.putInt("HOUR", hr); 
    bundle.putInt("MIN", min); 
    service.putExtras(bundle); 
    startService(service); 

} 

은 내가 서비스 실행의 여러 인스턴스를 가질 수

public void Stop(View view) { 
    hr = timePick.getCurrentHour(); 
    min = timePick.getCurrentMinute(); 
    Intent myAlarm = new Intent(this, MyAlarm.class); 
    Intent myService = new Intent(this, MyService.class); 
    Bundle bundle = new Bundle(); 
    bundle.putInt("HOUR", hr); 
    bundle.putInt("MIN", min); 
    myService.putExtras(bundle); 
    myAlarm.putExtras(bundle); 
    stopService(myAlarm); 
    stopService(myService); 
} 

하여 서비스를 중지합니다. 그러나 시간과 분을 전달하여 서비스의 단일 인스턴스를 중지하려고하면 서비스의 모든 인스턴스가 중지됩니다. MyService 서비스 내에서 alarmmanager를 사용했습니다. MyAlarm이 알림을 생성합니다.

예 : 나는 11.30과 11.40의 경보를 설정했다. 11.40에 대한 알람을 삭제하고 싶습니다. 그래서 나는 멈춤 버튼을 누른다. 그러나 두 알람은 ​​단지 문서

에서 onStartCommand 다시

를 호출하는 서비스의 다른 인스턴스를 시작하지 않습니다 startService(intent)를 호출, 동일한 서비스의 여러 인스턴스를 실행 같은 것은 없기 때문이다

답변

관련 문제