This appendix includes the answers to the end-of-chapter exercises.
android:theme onCreateDialog()startActivityForResult()dp unit is density independent and 1dp is equivalent to one pixel on a 160-dpi screen. The px unit corresponds to an actual pixel on screen. You should always use the dp unit because it enables your activity to scale properly when run on devices of varying screen size.AbsoluteLayout makes it difficult for your application to have a consistent look and feel across devices.onPause() event is fired whenever an activity is killed or sent to the background. The onSaveInstanceState() event is similar to the onPause() event, except that it is not always called, such as when the user presses the Back button to kill the activity.onPause(), onSaveInstanceState(), and onRetainNonConfigurationInstance(). onPause() method to preserve the activity's state because the method is always called when the activity is about to be destroyed.onSaveInstanceState() method to save the state of the activity (such as the data entered by the user) using a Bundle object.onRetainNonConfigurationInstance() method is useful for momentarily saving data (such as images or files downloaded from a web service) that might be too large to fit into a Bundle object.onCreateOptionsMenu() and onOptionsItemSelected() events.isChecked() method of each RadioButton to determine whether it has been selected.getResources() method. //—-get the current date—-
Calendar today = Calendar.getInstance();
yr = today.get(Calendar.YEAR);
month = today.get(Calendar.MONTH);
day = today.get(Calendar.DAY_OF_MONTH);
showDialog(DATE_DIALOG_ID);
ListFragment, DialogFragment, and PreferenceFragment. ListFragment is useful for displaying a list of items, such as an RSS listing of news items.DialogFragment allows you to display a dialog window modally and is useful when you want a response from the user before allowing him to continue with your application.PreferenceFragment displays a window containing your application's preferences and allows the user to edit them directly in your application.ImageSwitcher enables images to be displayed with animation. You can animate the image when it is being displayed, as well as when it is being replaced by another image.onCreateOptionsMenu() and onOptionsItemSelected().onCreateContextMenu() and onContextItemSelected().WebViewClient class and override the shouldOverrideUrlLoading() method.PreferenceActivity class.getExternalStorageDirectory().WRITE_EXTERNAL_STORAGE. Cursor c;
if (android.os.Build.VERSION.SDK_INT <11) {
//---before Honeycomb---
c = managedQuery(allContacts, projection,
ContactsContract.Contacts.DISPLAY_NAME + " LIKE ?",
new String[] {"%jack"},
ContactsContract.Contacts.DISPLAY_NAME + " ASC");
} else {
//---Honeycomb and later---
CursorLoader cursorLoader = new CursorLoader(
this,
allContacts,
projection,
ContactsContract.Contacts.DISPLAY_NAME + " LIKE ?",
new String[] {"%jack"},
ContactsContract.Contacts.DISPLAY_NAME + " ASC");
c = cursorLoader.loadInBackground();
}
getType(), onCreate(), query(), insert(), delete(), and update(). <provider android:name="BooksProvider"
android:authorities="net.learn2develop.provider.Books"/>
SEND_SMS and RECEIVE_SMS.onUpgrade()<uses-library> element in the AndroidManifest.xml fileINTERNET permission in the AndroidManifest.xml fileLocationManager.GPS_PROVIDERLocationManager.NETWORK_PROVIDERaddProximityAlert().INTERNET.JSONArray and JSONObject.AsyncTask.IntentService class is similar to the Service class except that it runs the tasks in a separate thread and automatically stops the service when the task has finished execution.doInBackground(), onProgressUpdate(), and onPostExecute().IntentFilter class.AsyncTask. This ensures that the UI is updated in a thread-safe manner.