내 타이머 용 AlarmManager를 사용하고 있습니다. 나는 2 개의 클래스가 있습니다. 나는 다음 코드를 사용하여 내 알람을 시작하고 첫 번째 클래스 (MainActivity)에서 Android AlarmManager 지속적으로 꺼짐
:public void startAlarm(long Seconds) {
Intent myIntent = new Intent(MainActivity.this, MyAlarmService.class);
pendingIntent = PendingIntent.getService(MainActivity.this, 13141337,
myIntent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.add(Calendar.SECOND, (int) Seconds);
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
pendingIntent);
}
알람이 울릴 다른 클래스 (AlarmSound)와 휴대폰이 진동에, 나는 전화 드렸습니다 내 취소 알람 방법.
public void stopAlarm(){
Intent intentstop = new Intent(AlarmSound.this, MyAlarmService.class);
PendingIntent senderstop = PendingIntent.getBroadcast(AlarmSound.this,
13141337, intentstop, 0);
AlarmManager myalarm = (AlarmManager) getSystemService(ALARM_SERVICE);
myalarm.cancel(senderstop);
Log.w("Karl","stopAlarm?");
}
올바른 방법입니까? 내 경보가 안드로이드 4.1에 끊임없이 나가기 때문에.
미리 감사드립니다.
답장을 보내 주셔서 감사합니다. setRepeating을 사용하면 문제가 해결되지 않습니까? 위의 코드를 사용하여 알람을 시작합니다. 나는 또한 stopself와 onStartCommand를 사용하지 않는다. 나는 내가 올바르게 끝내고 있다고 생각하니? 어떻게 확신 할 수 있습니까? 내 MainActivity에서 잘 작동하는 또 다른 stopAlarm 메서드가 있습니다. (테스트 등으로) 그것에 대해 확신합니다. 어떻게 AlarmSound에 stopAlarm을 사용할 수 있습니까? –
전체 AlarmSound 코드를 게시 할 수 있습니까? –
내 자신의 코드에 답할 수 없어서 pastebin을 사용했는데, http://pastebin.com/cnxY8mH5 거기에 있습니다. –