Mobile ProgrammingMidterm Review
Midterm Review
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
Layouts
• Linear, Relative, Table, Tab, FrameLayout.
• Draw a picture based on the layout.xml
Widgets
• TextViews, EditText, Button, SeekBar, RadioGroup, etc.
• Attributeso Ido Layout_widtho Layout_heighto textSizeo inputTypeo gravity
Toast and EvenHandling
• When and how to use Toast?
• Toast.makeText(context, “text”, Toast.LENGTH_SHORT).show().
• How to handle ClickEvent.
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
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()
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);
Explicit Intent vs Implicit Intent
• When do you want to use explicit intent
• When do you use implicit intent
• Intent Filters
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
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
Dialogs and Menus
• Dialogs
• Menuo optionMenuo contextMenu
• SharedPreferenceo Why do you use sharedPreferenceo How to access to your sharedPreference
Notifications
• What is a notification
• When do you use notifications?
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?
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)
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?
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?
Bound Service
• What is a bound service and how to use it.o Ibindero Messenger
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! */
}
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>
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
•Debugging
•Development
•Design
References
• The Busy Coder's Guide to Android Development - Mark Murphy
• Android Developers
• The Mobile Lab at Florida State University