SlideShare a Scribd company logo
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>

More Related Content

Viewers also liked (6)

PDF
Android ui dialog
Krazy Koder
 
PDF
Alertdialog in android
Durai S
 
PDF
Android ui menu
Krazy Koder
 
PDF
Android UI Development
Jussi Pohjolainen
 
PDF
Android notification
Krazy Koder
 
PPT
Android User Interface: Basic Form Widgets
Ahsanul Karim
 
Android ui dialog
Krazy Koder
 
Alertdialog in android
Durai S
 
Android ui menu
Krazy Koder
 
Android UI Development
Jussi Pohjolainen
 
Android notification
Krazy Koder
 
Android User Interface: Basic Form Widgets
Ahsanul Karim
 

Similar to Android L04 - Notifications and Threading (20)

PPTX
Introduction to google cloud messaging in android
RIA RUI Society
 
PDF
Push to Me: Mobile Push Notifications (Zend Framework)
Mike Willbanks
 
PPTX
GCM with Pushbots
Ashish RAj
 
PDF
Push-Notification
Amey Ruikar
 
PPTX
What's new in android M(6.0)
Yonatan Levin
 
PDF
Alarms
maamir farooq
 
PPTX
GCM Android
aswapnal
 
PDF
A Journey into Google Cloud Messaging
Simone Pulcini, OCMJEA6 OCUP
 
PDF
Android push-applications-android
wadise
 
PPTX
What's new in android jakarta gdg (2015-08-26)
Google
 
PDF
What's new in Android O
Kirill Rozov
 
PDF
GOOGLE CLOUD MESSAGING (GCM): A LIGHT WEIGHT COMMUNICATION MECHANISM BETWEEN ...
ijistjournal
 
PPT
Push Notification in IBM MobileFirst Xamarin SDK
Ajay Chebbi
 
PDF
Leveraging Zend Framework for Sending Push Notifications
Mike Willbanks
 
PPT
Google Cloud Messaging
Sandip Jadhav
 
PDF
Android 8 behavior changes
InnovationM
 
PDF
Mobile Push Notifications
Mike Willbanks
 
PDF
Google Cloud Messaging
Ashiq Uz Zoha
 
PDF
Zend Framework Push Notifications
Mike Willbanks
 
PDF
FOSS STHLM Android Cloud to Device Messaging
Johan Nilsson
 
Introduction to google cloud messaging in android
RIA RUI Society
 
Push to Me: Mobile Push Notifications (Zend Framework)
Mike Willbanks
 
GCM with Pushbots
Ashish RAj
 
Push-Notification
Amey Ruikar
 
What's new in android M(6.0)
Yonatan Levin
 
GCM Android
aswapnal
 
A Journey into Google Cloud Messaging
Simone Pulcini, OCMJEA6 OCUP
 
Android push-applications-android
wadise
 
What's new in android jakarta gdg (2015-08-26)
Google
 
What's new in Android O
Kirill Rozov
 
GOOGLE CLOUD MESSAGING (GCM): A LIGHT WEIGHT COMMUNICATION MECHANISM BETWEEN ...
ijistjournal
 
Push Notification in IBM MobileFirst Xamarin SDK
Ajay Chebbi
 
Leveraging Zend Framework for Sending Push Notifications
Mike Willbanks
 
Google Cloud Messaging
Sandip Jadhav
 
Android 8 behavior changes
InnovationM
 
Mobile Push Notifications
Mike Willbanks
 
Google Cloud Messaging
Ashiq Uz Zoha
 
Zend Framework Push Notifications
Mike Willbanks
 
FOSS STHLM Android Cloud to Device Messaging
Johan Nilsson
 
Ad

More from Mohammad Shaker (20)

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

Recently uploaded (20)

PPTX
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
PPTX
Engineering the Java Web Application (MVC)
abhishekoza1981
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PDF
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
DOCX
Import Data Form Excel to Tally Services
Tally xperts
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
PPTX
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PPTX
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
PPT
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
PDF
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 
The Role of a PHP Development Company in Modern Web Development
SEO Company for School in Delhi NCR
 
Engineering the Java Web Application (MVC)
abhishekoza1981
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
유니티에서 Burst Compiler+ThreadedJobs+SIMD 적용사례
Seongdae Kim
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
Import Data Form Excel to Tally Services
Tally xperts
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
Build It, Buy It, or Already Got It? Make Smarter Martech Decisions
bbedford2
 
Java Native Memory Leaks: The Hidden Villain Behind JVM Performance Issues
Tier1 app
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
How Apagen Empowered an EPC Company with Engineering ERP Software
SatishKumar2651
 
MergeSortfbsjbjsfk sdfik k
RafishaikIT02044
 
Linux Certificate of Completion - LabEx Certificate
VICTOR MAESTRE RAMIREZ
 

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>