Mobile Programming Midterm Review Agenda Layouts widgets toasts
Mobile Programming Midterm Review
Agenda • • • Layouts, widgets, toasts, and event. Handling Debuggings Resources, selections, activities, explicit intent Composite Views, activities, and implicit intent and filter Fragments, permissions, and Broadcast. Receiver Dialogs, Menus, Shared. Preferences. Notifications, Services, and Async. Tasks. Bound Services, location, sensors, and Intent. Filters Content. Providers
Layouts • Linear, Relative, Table, Tab, Frame. Layout. • Draw a picture based on the layout. xml
Widgets • Text. Views, Edit. Text, Button, Seek. Bar, Radio. Group, etc. • Attributes o o o Id Layout_width Layout_height text. Size input. Type gravity
Toast and Even. Handling • When and how to use Toast? • Toast. make. Text(context, “text”, Toast. LENGTH_SHORT). show(). • How to handle Click. Event.
Selections • Spinners o How to populate the spinner § Statically and dynamically o Array. Adapter o set. Adapter(adapter) • List. View • What is the difference bewteen the two. o on. Item. Selected. Listener o on. Item. Selected. Listern and on. Item. Click. Listener
Activity • • Activity Lifecycle o The sequence of methods being called when a user starts the activity. o The sequence of methods being called when the activity loses focus. Why do you need to override these lifecycle methods o on. Pause(), on. Resume(), on. Stop(), on. Destroy()
Pass Data Between Activities • Bundle o Check if the bundle is null! Bundle bundle = new Bundle(); bundle. put. String("fname", "John"); bundle. put. String("lname", "Doe"); bundle. put. Int("age", 18); intent. put. Extras(bundle); start. Activity(intent);
Explicit Intent vs Implicit Intent • When do you want to use explicit intent • When do you use implicit intent • Intent Filters
Fragments • Fragments o Neither a view nor activity o One activity can have multiple fragments • On. Create. View() returns a view. • How to pass data between activity and fragment o Set. Arguments(bundle) and get. Arguments() o Class public member variables • Removing and Replacing fragments
Permissions and Broadcast. Receiver • When should you use Broadcast. Receivers? • Override the on. Receive() method • How to statistically register your Broadcast. Receiver? • How to dynamically register your Broadcast. Receiver? o When do your register o When do your unregister
Dialogs and Menus • Dialogs • Menu o option. Menu o context. Menu • Shared. Preference o Why do you use shared. Preference o How to access to your shared. Preference
Notifications • • What is a notification When do you use notifications?
Service • What is a service? o Perform a longer-running operation o Running in the background o The service and the UI activity share the same process • Service Lifecycle o on. Create(), on. Start. Command(), on. Destroy(), etc • Service and Intent. Service. o When do you use which?
Service • How to communicate between service and activity o Broadcast Intent o Pending Result (on. Activity. Result()) o Messenger • Messenger is parcelable, so it can be put in a bundle. o Override handle. Message(Message msg)
Async Task • Multi-threading o Allows you to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers. o Easy the use of main UI thread o Publish the result to the UI when it is needed. • What is the difference between using service and Async task?
Async Task • Multi-threading o Allows you to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers. o Easy the use of main UI thread o Publish the result to the UI when it is needed. • What is the difference between using service and Async task?
Bound Service • What is a bound service and how to use it. o Ibinder o Messenger
Start. Activity and Get. Result • start. Activity. For. Result(intent, PICK_REQUEST); protected void on. Activity. Result(int request. Code, int result. Code, Intent data) { if (request. Code == PICK_REQUEST) { if (result. Code == RESULT_OK) { /* result is OK! */ }
Midterm Exam • When to use a content provider? o Content. Resolver • Content provider vs shared. Preference? • Permissions. o Protect your content provider because By default, anyone can read from or write to your content provider. o <provider> § Android: read. Permission=edu. tian. provider. permission. READ § Android: write. Permission=edu. tian. provider. permission. WRITE o <permission android: name=edu. tian. provider. permission. READ>
Content Provider • • Short answers Debugging o Given a code example, find errors and fix them • Development o Given a code example, complete the example. • Design • Extra Credits
• • • Debugging Development Design
References • The Busy Coder's Guide to Android Development - Mark Murphy • Android Developers • The Mobile Lab at Florida State University
- Slides: 23