2013-12-10 2 views
0

Я новичок в android, я хочу запустить задачу только на определенную продолжительность, как я могу это сделать? Я пробовал использовать широковещательный приемник и AlarmManager, но трансляционный транслятор постоянно работает даже по прошествии определенного времени.Запуск Broadcastreceiver за указанное время

long timetorun= calendarcurrent.getTimeInMillis() - calendar.getTimeInMillis(); 
Intent c = new Intent(getApplicationContext(), 
Phonecallreceiver.class); 
pintent = PendingIntent.getBroadcast(getApplicationContext(), 0, c, 0); 
AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE); 
alarm.set(AlarmManager.RTC_WAKEUP, timetorun, pintent); 

ответ

0

Вы можете остановить его отмены тревоги, используя тот же PendingIntent как ниже:

Intent c = new Intent(getApplicationContext(), Phonecallreceiver.class); 
pintent = PendingIntent.getBroadcast(getApplicationContext(), 0, c, 0); 
AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE); 
alarm .cancel(pintent); 

Не забудьте убедиться, что PendingIntent не NULL. Надеюсь, что я вам помог.

+0

Проблема в том, что я не знаю точного момента, чтобы позвонить ** alarm.cancel (pintent) ** – Psypher

Смежные вопросы