Overview
● Retro
o Lesson 3 activities & intents
● Looking forward
o Lesson 4 lifecycles & databases
● Stickers + Booklets
● Next Tue 7-8pm SpacePortX
Prime Directive
‘Regardless of where we are up to, we
understand and truly believe that
everyone did the best job he or she
could, given his or her skills and
abilities, the personal time available,
and the situation at hand.’
Difficulty Check
● Who completed the class?
● How long did it take?
● Hands up 1-10 difficulty of the weeks lesson
● Any specific areas of the lesson that require particular
focus?
Retro activities & intents
What we learnt last week
● Toast UI feedback
● Creating the detail activity
● Navigation with Intents
● Settings with Preference Activity
● Remembering location with Shared Preferences
● ShareActionProvider
Lesson 3 - Toast● Toast.makeText(activity, “Oh hai”, Toast.LENGTH_SHORT);
● Popup that displays a message for a few seconds before fading out
● Useful for debugging to give visual feedback without changing app UI
● Always remember to use the .show() method
● Toast is still an Android View so needs to be controlled from the Main
Thread
● You can customise a toast and use your own layout
● Whenever you want your app components to talk to each other or talk to the system you use an
Intent to specify the destination
● Intent is like an envelope
o Address of who to talk to
o Space to attach data
● Explicit Intent
o Intent with class name DetailActivity.class
● Implicit Intent
o Intent with data around an action to perform http://google.com
● Intents can cross the application (process) boundary
Lesson 3 - Intents
Lesson 3 - PreferenceActivity
● Hierarchy of preferences
● UI is done for you
o checkbox, list, edittext, switch preferences
● Custom Preferences
● Preference XML file defining layout
● Manually monitor for preference changes to update UI
● Gingerbread does not have (easily) nested preferences
● Saves into Default SharedPreferences file
● Save Java primitive
Lesson 3 - SharedPreferences
● Key Value pairs
● PreferenceManager.getDefaultSharedPreferences()
● Context.getSharedPreferences()
● SharedPreferences.Editor
● MODE_PRIVATE , MODE_WORLD_READABLE / WRITEABLE
○ ContentProvider, Service, Broadcast
● commit() vs apply()
○ apply added in SDK 9 (2.3 Gingerbread)
Lesson 3 - ShareActionProvider
● Share Intent
● Add ShareActionProvider in XML menu
● Add Intent to ShareActionProvider
● Photos, apps, videos, general links
● No need to know what apps are available
● 4.0 and above (plus support library)
● important to jump out of task
o FLAG_ACTIVITY_CLEAR_WHEN_RESET
Lesson 3 - BroadcastReceiver
● Extend BroadcastReceiver
● Register programmatically
○ remember to unregister!
● Register via AndroidManifest
● IntentFilter to select messages to
listen to
● 10 seconds to react
○ finish your work
○ start another component
What went well
- Seeing the wire frames and talking UX
- Breakpoints
- ShareActionProvider is so easy & bonus
functionality
What didn’t go so well
- PreferenceActivity changes monitoring
- Writing implicit intent to start map activity ( a
lot of googling )- https://developer.android.com/guide/components/int
ents-common.html#Maps
- Add namespace manually for support library
widget xml (ShareActionProvider)
Next Lesson - Activity Lifecycle & Data
Learning Objectives:- Activity lifecycle
- Active and visible lifetime.
- Saving Activity State
- Databases
- ContentProviders basics.
See you next week..
- Time: Tuesday 7pm
- Place: SpacePort
- Things needed: You + Questions +
Feedback
- Can contact us if issues:
@blundell_apps / @android_mcr