This appendix includes the answers to the end of chapter exercises.
An AVD is an Android Virtual Device. It represents an Android Emulator, which emulates a particular configuration of an actual Android device.
The android:versionCode
attribute is used to programmatically check if an application can be upgraded. It should contain a running number (an updated application should be set to a higher number than the older version). The android:versionName
attribute is used mainly for displaying to the user. It is a string, such as "1.0.1".
The strings.xml
file is used to store all string constants in your application. This enables you to easily localize your application by simply replacing the strings and then recompiling your application.
The Android OS will display a dialog from which users can choose which activity they want to use.
Intent i = new
Intent(android.content.Intent.ACTION_VIEW,
Uri.parse
("http://www.amazon.com"));
startActivity(i);
In an intent filter, you can specify the following: action, data, type, and category.
The Toast
class is used to display alerts to the user and disappears after a few seconds. The NotificationManager
class is used to display notifications on the device's status bar. The alert displayed by the NotificationManager
class is persistent and can only be dismissed by the user when selected.
The dp
unit is density independent and 160dp is equivalent to one inch. 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.
With the advent of devices with different screen sizes, using the AbsoluteLayout
makes it difficult for your application to have a consistent look and feel across devices.
The onPause()
event is fired whenever an activity is killed or sent to the background. The onSaveInstanceState()
event is like the onPause()
event, except that it is not always called, such as when the user presses the Back button to kill the activity.
The three events are onPause()
, onSaveInstanceState()
, and onRetainNonConfigurationInstance()
.
You should check the isChecked()
method of each RadioButton
to determine if it has been checked.
The code snippet to obtain the current date is as follows:
//---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);
The 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.
The two methods are onCreateOptionsMenu()
and on OptionsItemSelected()
.
The two methods are onCreateContextMenu()
and onContextItemSelected()
.
To prevent launching the device's web browser, you need to implement the WebViewClient
class and override the shouldOverrideUrlLoading()
method.
The code is as follows:
Cursor c = managedQuery( allContacts, projection, ContactsContract.Contacts.DISPLAY_NAME + " LIKE ?", new String[] {"%jack%"}, ContactsContract.Contacts.DISPLAY_NAME + " ASC");
The methods are getType()
, onCreate()
, query()
, insert()
, delete()
, and update()
.
The code is as follows:
<provider android:name="BooksProvider" android:authorities="net.learn2develop.provider.Books" />
You can either programmatically send a SMS message from within your Android application or invoke the built-in Messaging application to send it on your application's behalf.
The Broadcast receiver should fire a new intent to be received by the activity. The activity should implement another BroadcastReceiver
to listen for this new intent.
This is because a service runs on the same process as the calling activity. If a service is long-running, you need to run it on a separate thread so that it does not block the activity.
The 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.
The three methods are doInBackground()
, onProgressUpdate()
, and onPostExecute()
.
The service can broadcast an intent, and the activity can register an intent using an IntentFilter
class.
You specify the minimum Android version required using the minSdkVersion
attribute in the AndroidManifest.xml
file.
You can either use the keytool.exe utility from the Java SDK, or use Eclipse's Export feature to generate a certificate.
Go to the Settings application and select the Applications item. Check the "Unknown sources" item.
3.15.179.121