mobile programming midterm review. agenda layouts, widgets, toasts, and eventhandling debuggings...

23
Mobile Programming Midterm Review Midterm Review

Upload: philippa-cooper

Post on 13-Dec-2015

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Mobile ProgrammingMidterm Review

Midterm Review

Page 2: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Agenda

• Layouts, widgets, toasts, and eventHandling

• Debuggings

• Resources, selections, activities, explicit intent

• Composite Views, activities, and implicit intent and filter

• Fragments, permissions, and BroadcastReceiver

• Dialogs, Menus, SharedPreferences.

• Notifications, Services, and AsyncTasks.

• Bound Services, location, sensors, and IntentFilters

• ContentProviders

Page 3: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Layouts

• Linear, Relative, Table, Tab, FrameLayout.

• Draw a picture based on the layout.xml

Page 4: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Widgets

• TextViews, EditText, Button, SeekBar, RadioGroup, etc.

• Attributeso Ido Layout_widtho Layout_heighto textSizeo inputTypeo gravity

Page 5: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Toast and EvenHandling

• When and how to use Toast?

• Toast.makeText(context, “text”, Toast.LENGTH_SHORT).show().

• How to handle ClickEvent.

Page 6: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Selections

• Spinnerso How to populate the spinner

Statically and dynamicallyo ArrayAdaptero setAdapter(adapter)

• ListView

• What is the difference bewteen the two.o onItemSelectedListenero onItemSelectedListern and onItemClickListener

Page 7: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Activity

• Activity Lifecycleo 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 methodso onPause(), onResume(), onStop(), onDestroy()

Page 8: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Pass Data Between Activities

• Bundleo Check if the bundle is null!

Bundle bundle = new Bundle();

bundle.putString("fname","John");

bundle.putString("lname", "Doe");

bundle.putInt("age", 18);

intent.putExtras(bundle);

startActivity(intent);

Page 9: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Explicit Intent vs Implicit Intent

• When do you want to use explicit intent

• When do you use implicit intent

• Intent Filters

Page 10: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Fragments

• Fragmentso Neither a view nor activityo One activity can have multiple fragments

• OnCreateView() returns a view.

• How to pass data between activity and fragmento SetArguments(bundle) and getArguments() o Class public member variables

• Removing and Replacing fragments

Page 11: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Permissions and BroadcastReceiver

• When should you use BroadcastReceivers?

• Override the onReceive() method

• How to statistically register your BroadcastReceiver?

• How to dynamically register your BroadcastReceiver?o When do your registero When do your unregister

Page 12: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Dialogs and Menus

• Dialogs

• Menuo optionMenuo contextMenu

• SharedPreferenceo Why do you use sharedPreferenceo How to access to your sharedPreference

Page 13: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Notifications

• What is a notification

• When do you use notifications?

Page 14: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Service

• What is a service?o Perform a longer-running operationo Running in the backgroundo The service and the UI activity share the same process

• Service Lifecycleo onCreate(), onStartCommand(), onDestroy(), etc

• Service and IntentService.o When do you use which?

Page 15: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Service

• How to communicate between service and activityo Broadcast Intento Pending Result (onActivityResult())o Messenger

• Messenger is parcelable, so it can be put in a bundle.o Override handleMessage(Message msg)

Page 16: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Async Task

• Multi-threadingo 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 threado Publish the result to the UI when it is needed.

• What is the difference between using service and Async task?

Page 17: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Async Task

• Multi-threadingo 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 threado Publish the result to the UI when it is needed.

• What is the difference between using service and Async task?

Page 18: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Bound Service

• What is a bound service and how to use it.o Ibindero Messenger

Page 19: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

StartActivity and GetResult

• startActivityForResult(intent, PICK_REQUEST);

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

if (requestCode == PICK_REQUEST) {

if (resultCode == RESULT_OK) {

/* result is OK! */

}

Page 20: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Midterm Exam

• When to use a content provider?o ContentResolver

• Content provider vs sharedPreference?

• Permissions.o Protect your content provider because By default, anyone can read from

or write to your content provider.o <provider>

Android:readPermission=edu.tian.provider.permission.READ Android:writePermission=edu.tian.provider.permission.WRITE

o <permission android:name=edu.tian.provider.permission.READ>

Page 21: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

Content Provider

• Short answers

• Debuggingo Given a code example, find errors and fix them

• Developmento Given a code example, complete the example.

• Design

• Extra Credits

Page 22: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

•Debugging

•Development

•Design

Page 23: Mobile Programming Midterm Review. Agenda Layouts, widgets, toasts, and eventHandling Debuggings Resources, selections, activities, explicit intent Composite

References

• The Busy Coder's Guide to Android Development - Mark Murphy

• Android Developers

• The Mobile Lab at Florida State University