Android Alarms & Broadcast Receivers

1,091
-1

Published on

Published in: Self Improvement
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,091
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Android Alarms & Broadcast Receivers

  1. 1. Alarms andBroadcast Receivers Razvan Prejbeanu Eduard Dorobanțu
  2. 2. Cuprins• AlarmManager o Scop o Implementare o Rezultate obtinute• BroadcastReceiver o Scop o Implementare o Rezultate obtinute
  3. 3. Alarm Manager - Scop -• Pentru a rula cod la un moment de timp specific, fara a-l lega de o activitate a aplicatiei• Pentru a programa operatii la intervale de timp• Pentru a ne asigura ca o zona de cod se executa atomic ( se obtine un wake lock asupra sistemului)
  4. 4. Alarm Manager - Implementare -• Clasa AlarmManager - acces la Android AlarmService• Alarme one-time sau repeating• La timpul prestabilit - Intent trimis in sistem (prins de BroadcastReceiver, Service sau Activity)• 4 tipuri de alarme: o RTC
  5. 5. - Implementare (2) - Obtinerea unei instante: One time alarm:
  6. 6. - Implementare (3) - Repeating Alarms: o setRepeating(int type, long triggerAtMillis, long intervalMillis, PendingIntent operation ) o setInexactRepeating(int type, long triggerAtMillis, long intervalMillis, PendingIntent operation ) Oprirea unei alarme repetitive:
  7. 7. Alarm Manager - Rezultate obținute -• Show notification• Start service• Start Activity• Trigger Broadcast Receiver
  8. 8. Broadcast Receivers - Scop -• Extind clasa BroadcastReceiver• Recepționeaza si reacționeaza la primirea anunțurilor de tip Broadcast
  9. 9. Broadcast Receivers - Implementare -• Extindere clasa BroadcastReceiver• Inregistrare receiver in AndroidManifest o numele clasei o intent-filter - acele Intents la care asculta receiver-ul
  10. 10. - Implementare (2) -• Se recepționează Broadcast Intents prin metoda onReceive() din BroadcastReceiver• Se trimit Broadcasts prin sendBroadcast(Intent sourceIntent):
  11. 11. Broadcast Receivers - Rezultate obținute -• Sunt receptionate diverse stări ale serviciilor telefonului: o low battery o power connected o shutdown o receiving phone call
  12. 12. Putting them together• Alarm Manager inițiaza Broadcast o sendBroadcast();• Broadcast Receiver recepționeaza anunțul de tip Broadcast o receiveBroadcast();• Broadcast Receiver reacționeaza și rezolva acest tip de anunț
  13. 13. Concluzii• Folosite pentru creearea unei aplicații ce amintește utilizatorului de existența si de modificările sale
  14. 14. Documentatie• http://www.developer.android.com• http://www.vogella.com/articles/AndroidBroadcastRecei ver/article.html• http://www.androidcompetencycenter.com/2009/02/andr oid-basics-alarm-service
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×