Java Reference
In-Depth Information
uninstall
Java7MeetsAndroid
.Youmustspecifytheapp'spackagenametounin-
stall it.
EXERCISES
ThefollowingexercisesaredesignedtotestyourunderstandingofAndroidappde-
velopment:
SimpleActivity.java
source file. You should end up with a
SimpleApp-debug.apk
fileinthe
bin
subdirectory.(Hint:you'llneed
to use the
android
tool's
-n
command-line option.) Install this APK on
the running test_AVD emulated device.
2. Whenyouviewthisapp'siconandlabelontheapplauncherscreen,you'll
notice that the label says
SimpleActivity
instead of
SimpleApp
.
Why?
3. How would you uninstall
SimpleApp
from test_AVD?
4. Expand
SimpleApp
by including a
SimpleActivity2.java
source
file whose
onCreate(Bundle)
method is similar to
SimpleActiv-
ity.java
's
onCreate(Bundle)
method but consists of
su-
per.onCreate(savedInstanceState);
followed by
Toast.makeText(this, getIntent().toString(),
Toast.LENGTH_LONG).show();
. (The
android.widget.Toast
classisusefulforbrieflydisplayingshortdebuggingmessagesinlieuofus-
ing
System.out.println()
, whose output can be viewed only after
invoking
adb logcat
. Because so many messages are output to this
log,itcanbedifficulttolocate
System.out.println()
content,which
is why you'll probably find
Toast
to be more useful.) Refactor
Sim-
pleActivity
's
onCreate(Bundle)
method to start
Sim-
pleActivity2
via an implicit intent, as demonstrated earlier in this
chapter.
5. Continuing from Exercise 4, create
SimpleApp
(make sure to refactor
AndroidManifest.xml
to account for
SimpleActivity2
). After
installing the refactored
SimpleApp
, click its app launcher
StartActivity
icon. What happens?