SlideShare una empresa de Scribd logo
1 de 23
Descargar para leer sin conexión
Cloud
InteractionDesign
Android
Toast
Toast
Toast
Context  context  =  getApplicationContext();                 
CharSequence text  =  "Hello  toast!";                
int duration  =  Toast.LENGTH_SHORT;                 
Toast  toast  =  Toast.makeText(context,   text,  duration);                
toast.show();
Notifications
Notifications
Five priority levels:
– PRIORITY_MIN (-2) to PRIORITY_MAX (2);
– if not set, the priority defaults to PRIORITY_DEFAULT (0).
NotificationsPriorities
Notifications
NotificationCompat.Builder mBuilder = new  
NotificationCompat.Builder(this)                                                 
.setSmallIcon(android.R.drawable.stat_notify_more)                                               
.setContentTitle("My   notification")                                                 
.setContentText("Hello   World!");
Notifications
NotificationCompat.Builder mBuilder = new  
NotificationCompat.Builder(this)                                                 
.setSmallIcon(android.R.drawable.stat_notify_more)                                               
.setContentTitle("My   notification")                                                 
.setContentText("Hello   World!");
Threads
UI Thread, AsyncTask, Handler
BroadcastReceiver class
Alarms
Alarms / Scheduling
Google Cloud Messaging (GCM)
with SyncAdapter
Alarms Use Cases
• MMS – Retry Scheduler
• Bluetooth [Discoverable] Timeout
• Notifications
• Syncing data with the server
• ..etc.
Alarms Firing
• ELAPSED_REALTIME
– Fires the pending intent based on the amount of time since the device was booted, but doesn't
wake up the device. The elapsed time includes any time during which the device was asleep.
• ELAPSED_REALTIME_WAKEUP
– Wakes up the device and fires the pending intent after the specified length of time has elapsed
since device boot.
• RTC
– Fires the pending intent at the specified time but does not wake up the device.
• RTC_WAKEUP
– Wakes up the device to fire the pending intent at the specified time.
https://developer.android.com/training/scheduling/alarms.html
ELAPSED_REALTIME_WAKEUP
private  AlarmManager alarmMgr;
alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
AlarmManager.INTERVAL_HALF_HOUR,
AlarmManager.INTERVAL_HALF_HOUR,  alarmIntent);
RTC
private  AlarmManager alarmMgr;
//  Set  the  alarm  to  start  at  approximately  2:00  p.m.
Calendar  calendar  =  Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY,  14);
alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP,  
calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY,
alarmIntent);
Back to
BroadcastReceiver
class
Fire Alarm on Booting Example
BroadcastReceiver on Booting
• Add a permission:
<uses-­‐permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
• Implement a BroadcastReceiver called SampleBootReceiver:
public  class  SampleBootReceiver extends  BroadcastReceiver {
@Override
public  void  onReceive(Context  context,  Intent  intent)  {
if  (intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))  {
//  Set  the  alarm  here.
}
}
}
• Set the SampleBootReceiver to fire on Boot:
<receiver  android:name=".SampleBootReceiver"
android:enabled="false">
<intent-­‐filter>
<action  android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-­‐filter>
</receiver>
BroadcastReceiver on Booting
• Add a permission:
<uses-­‐permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
• Implement a BroadcastReceiver called SampleBootReceiver:
public  class  SampleBootReceiver extends  BroadcastReceiver {
@Override
public  void  onReceive(Context  context,  Intent  intent)  {
if  (intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))  {
//  Set  the  alarm  here.
}
}
}
• Set the SampleBootReceiver to fire on Boot:
<receiver  android:name=".SampleBootReceiver"
android:enabled="false">
<intent-­‐filter>
<action  android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-­‐filter>
</receiver>
BroadcastReceiver on Booting
• Add a permission:
<uses-­‐permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
• Implement a BroadcastReceiver called SampleBootReceiver:
public  class  SampleBootReceiver extends  BroadcastReceiver {
@Override
public  void  onReceive(Context  context,  Intent  intent)  {
if  (intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))  {
//  Set  the  alarm  here.
}
}
}
• Set the SampleBootReceiver to fire on Boot:
<receiver  android:name=".SampleBootReceiver"
android:enabled="false">
<intent-­‐filter>
<action  android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-­‐filter>
</receiver>

Más contenido relacionado

Destacado (6)

Android ui dialog
Android ui dialogAndroid ui dialog
Android ui dialog
 
Alertdialog in android
Alertdialog in androidAlertdialog in android
Alertdialog in android
 
Android ui menu
Android ui menuAndroid ui menu
Android ui menu
 
Android UI Development
Android UI DevelopmentAndroid UI Development
Android UI Development
 
Android notification
Android notificationAndroid notification
Android notification
 
Android User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAndroid User Interface: Basic Form Widgets
Android User Interface: Basic Form Widgets
 

Similar a Android L04 - Notifications and Threading

Similar a Android L04 - Notifications and Threading (20)

The Timer
The TimerThe Timer
The Timer
 
How to build typing indicator in a Chat app
How to build typing indicator in a Chat appHow to build typing indicator in a Chat app
How to build typing indicator in a Chat app
 
6. TinyOS_2.pdf
6. TinyOS_2.pdf6. TinyOS_2.pdf
6. TinyOS_2.pdf
 
Sierraware ARM hypervisor
Sierraware ARM hypervisor Sierraware ARM hypervisor
Sierraware ARM hypervisor
 
Pandora FMS: Windows Phone 7 Agent
Pandora FMS: Windows Phone 7 AgentPandora FMS: Windows Phone 7 Agent
Pandora FMS: Windows Phone 7 Agent
 
Manual of the CSS Alarm Handler (Beast)
Manual of the CSS Alarm Handler (Beast)Manual of the CSS Alarm Handler (Beast)
Manual of the CSS Alarm Handler (Beast)
 
Lab 1 new
Lab 1 newLab 1 new
Lab 1 new
 
Study of arduino for irrigation based control using android app
Study of arduino for irrigation based control using android appStudy of arduino for irrigation based control using android app
Study of arduino for irrigation based control using android app
 
How to Create a Countdown Timer in Python.pdf
How to Create a Countdown Timer in Python.pdfHow to Create a Countdown Timer in Python.pdf
How to Create a Countdown Timer in Python.pdf
 
Android tutorial (2)
Android tutorial (2)Android tutorial (2)
Android tutorial (2)
 
Introduction to Android Wear
Introduction to Android WearIntroduction to Android Wear
Introduction to Android Wear
 
GCM aperitivo Android
GCM aperitivo AndroidGCM aperitivo Android
GCM aperitivo Android
 
MSMQ - Microsoft Message Queueing
MSMQ - Microsoft Message QueueingMSMQ - Microsoft Message Queueing
MSMQ - Microsoft Message Queueing
 
Manage all the things, small and big, with open source LwM2M implementations ...
Manage all the things, small and big, with open source LwM2M implementations ...Manage all the things, small and big, with open source LwM2M implementations ...
Manage all the things, small and big, with open source LwM2M implementations ...
 
Local Notification Tutorial
Local Notification TutorialLocal Notification Tutorial
Local Notification Tutorial
 
Break Timer: Android-wear introduction and application case-study
Break Timer: Android-wear introduction and application case-studyBreak Timer: Android-wear introduction and application case-study
Break Timer: Android-wear introduction and application case-study
 
RTOS implementation
RTOS implementationRTOS implementation
RTOS implementation
 
Free rtos workshop3@nuu
Free rtos workshop3@nuuFree rtos workshop3@nuu
Free rtos workshop3@nuu
 
Broadcast Receiver
Broadcast ReceiverBroadcast Receiver
Broadcast Receiver
 
Connecting IBM MessageSight to the Enterprise
Connecting IBM MessageSight to the EnterpriseConnecting IBM MessageSight to the Enterprise
Connecting IBM MessageSight to the Enterprise
 

Más de Mohammad Shaker

Más de Mohammad Shaker (20)

12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate12 Rules You Should to Know as a Syrian Graduate
12 Rules You Should to Know as a Syrian Graduate
 
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
Ultra Fast, Cross Genre, Procedural Content Generation in Games [Master Thesis]
 
Interaction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with PsychologyInteraction Design L06 - Tricks with Psychology
Interaction Design L06 - Tricks with Psychology
 
Short, Matters, Love - Passioneers Event 2015
Short, Matters, Love -  Passioneers Event 2015Short, Matters, Love -  Passioneers Event 2015
Short, Matters, Love - Passioneers Event 2015
 
Unity L01 - Game Development
Unity L01 - Game DevelopmentUnity L01 - Game Development
Unity L01 - Game Development
 
Android L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and WearablesAndroid L07 - Touch, Screen and Wearables
Android L07 - Touch, Screen and Wearables
 
Interaction Design L03 - Color
Interaction Design L03 - ColorInteraction Design L03 - Color
Interaction Design L03 - Color
 
Interaction Design L05 - Typography
Interaction Design L05 - TypographyInteraction Design L05 - Typography
Interaction Design L05 - Typography
 
Interaction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and CouplingInteraction Design L04 - Materialise and Coupling
Interaction Design L04 - Materialise and Coupling
 
Android L05 - Storage
Android L05 - StorageAndroid L05 - Storage
Android L05 - Storage
 
Android L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOSAndroid L09 - Windows Phone and iOS
Android L09 - Windows Phone and iOS
 
Interaction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile ConstraintsInteraction Design L01 - Mobile Constraints
Interaction Design L01 - Mobile Constraints
 
Interaction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and GridsInteraction Design L02 - Pragnanz and Grids
Interaction Design L02 - Pragnanz and Grids
 
Android L10 - Stores and Gaming
Android L10 - Stores and GamingAndroid L10 - Stores and Gaming
Android L10 - Stores and Gaming
 
Android L06 - Cloud / Parse
Android L06 - Cloud / ParseAndroid L06 - Cloud / Parse
Android L06 - Cloud / Parse
 
Android L08 - Google Maps and Utilities
Android L08 - Google Maps and UtilitiesAndroid L08 - Google Maps and Utilities
Android L08 - Google Maps and Utilities
 
Indie Series 03: Becoming an Indie
Indie Series 03: Becoming an IndieIndie Series 03: Becoming an Indie
Indie Series 03: Becoming an Indie
 
Indie Series 01: Intro to Games
Indie Series 01: Intro to GamesIndie Series 01: Intro to Games
Indie Series 01: Intro to Games
 
Indie Series 04: The Making of SyncSeven
Indie Series 04: The Making of SyncSevenIndie Series 04: The Making of SyncSeven
Indie Series 04: The Making of SyncSeven
 
Indie Series 02: AI and Recent Advances in Games
Indie Series 02: AI and Recent Advances in GamesIndie Series 02: AI and Recent Advances in Games
Indie Series 02: AI and Recent Advances in Games
 

Último

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Último (20)

ManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide DeckManageIQ - Sprint 236 Review - Slide Deck
ManageIQ - Sprint 236 Review - Slide Deck
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park %in ivory park+277-882-255-28 abortion pills for sale in ivory park
%in ivory park+277-882-255-28 abortion pills for sale in ivory park
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 

Android L04 - Notifications and Threading

  • 4. Toast Context  context  =  getApplicationContext();                 CharSequence text  =  "Hello  toast!";                 int duration  =  Toast.LENGTH_SHORT;                 Toast  toast  =  Toast.makeText(context,   text,  duration);                 toast.show();
  • 7. Five priority levels: – PRIORITY_MIN (-2) to PRIORITY_MAX (2); – if not set, the priority defaults to PRIORITY_DEFAULT (0). NotificationsPriorities
  • 8. Notifications NotificationCompat.Builder mBuilder = new   NotificationCompat.Builder(this)                                                 .setSmallIcon(android.R.drawable.stat_notify_more)                                               .setContentTitle("My   notification")                                                 .setContentText("Hello   World!");
  • 9. Notifications NotificationCompat.Builder mBuilder = new   NotificationCompat.Builder(this)                                                 .setSmallIcon(android.R.drawable.stat_notify_more)                                               .setContentTitle("My   notification")                                                 .setContentText("Hello   World!");
  • 14. Google Cloud Messaging (GCM) with SyncAdapter
  • 15. Alarms Use Cases • MMS – Retry Scheduler • Bluetooth [Discoverable] Timeout • Notifications • Syncing data with the server • ..etc.
  • 16. Alarms Firing • ELAPSED_REALTIME – Fires the pending intent based on the amount of time since the device was booted, but doesn't wake up the device. The elapsed time includes any time during which the device was asleep. • ELAPSED_REALTIME_WAKEUP – Wakes up the device and fires the pending intent after the specified length of time has elapsed since device boot. • RTC – Fires the pending intent at the specified time but does not wake up the device. • RTC_WAKEUP – Wakes up the device to fire the pending intent at the specified time. https://developer.android.com/training/scheduling/alarms.html
  • 18. RTC private  AlarmManager alarmMgr; //  Set  the  alarm  to  start  at  approximately  2:00  p.m. Calendar  calendar  =  Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); calendar.set(Calendar.HOUR_OF_DAY,  14); alarmMgr.setInexactRepeating(AlarmManager.RTC_WAKEUP,   calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, alarmIntent);
  • 20. Fire Alarm on Booting Example
  • 21. BroadcastReceiver on Booting • Add a permission: <uses-­‐permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> • Implement a BroadcastReceiver called SampleBootReceiver: public  class  SampleBootReceiver extends  BroadcastReceiver { @Override public  void  onReceive(Context  context,  Intent  intent)  { if  (intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))  { //  Set  the  alarm  here. } } } • Set the SampleBootReceiver to fire on Boot: <receiver  android:name=".SampleBootReceiver" android:enabled="false"> <intent-­‐filter> <action  android:name="android.intent.action.BOOT_COMPLETED"></action> </intent-­‐filter> </receiver>
  • 22. BroadcastReceiver on Booting • Add a permission: <uses-­‐permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> • Implement a BroadcastReceiver called SampleBootReceiver: public  class  SampleBootReceiver extends  BroadcastReceiver { @Override public  void  onReceive(Context  context,  Intent  intent)  { if  (intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))  { //  Set  the  alarm  here. } } } • Set the SampleBootReceiver to fire on Boot: <receiver  android:name=".SampleBootReceiver" android:enabled="false"> <intent-­‐filter> <action  android:name="android.intent.action.BOOT_COMPLETED"></action> </intent-­‐filter> </receiver>
  • 23. BroadcastReceiver on Booting • Add a permission: <uses-­‐permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/> • Implement a BroadcastReceiver called SampleBootReceiver: public  class  SampleBootReceiver extends  BroadcastReceiver { @Override public  void  onReceive(Context  context,  Intent  intent)  { if  (intent.getAction().equals("android.intent.action.BOOT_COMPLETED"))  { //  Set  the  alarm  here. } } } • Set the SampleBootReceiver to fire on Boot: <receiver  android:name=".SampleBootReceiver" android:enabled="false"> <intent-­‐filter> <action  android:name="android.intent.action.BOOT_COMPLETED"></action> </intent-­‐filter> </receiver>