Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Make your likes visible on Facebook?

Connect your Facebook account to Prezi and let your likes appear on your timeline.
You can change this under Settings & Account at any time.

No, thanks

Android Bootcamp Week 1

No description
by

Mary-Anne Cosgrove

on 22 March 2014

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Android Bootcamp Week 1

Android Bootcamp Week 1
design by Dóri Sirály for Prezi
You've created a new Android App
What the heck is all this stuff?
Running the App
in the Genymotion Emulator
Exercise 1: Explore the Lifecycle
Run the newly created application on the
Genymotion
emulator

Try filtering
LogCat
to your
androidbootcamp
package

Move the
HelloAndroid
activity to a new controller package

Use
Code > Generate
to generate overrides for
onDestroy(), onStart(), onStop(), onPause(), onResume()
and
onRestart().

Add a log statement to each of these as well as
onCreate()
:
Log.d("lifecycle", "HelloAndroid <method>");

Filter
LogCat
to the "
lifecycle
" tag, then explore when these messages are produced. What happens when you change from portrait to landscape?
Summary
You've dissected an Android and seen:
Activities
Resources
The Manifest
You've run your app on an emulator
You've created your own activity so the user can enter their name
You've explored the Android life-cycle
Hello Android
Goals:
Develop a working Android app and explore its anatomy.
Allow the user to enter their name.

Next week...
Next week on
Android Bootcamp:

Behaviour Driven Development
with Android
Retrospective...
What did we do well?
What could we do better?
What puzzles you?
Why are we here?
To learn about Android application development together

To build a simple game incrementally over six weeks
Treasure Hunt
Score points by finding 'treasures' in our local area
The Android Activity Life-Cycle
512x512 image
for the Play store
Resources: Static files
to be packaged
with the app

These form the
View,
and exist to
keep the
view
separate
from the
model
and
controller
code
Drawables
: Images in various
resolutions for different screen densities.

9 patches
allow you to control how images get stretched. Extension is .9.png

You can use image files from the platforms/data/res directory of the Android SDK under the Apache License 2.0, or create your own with the help of the
Android Asset Studio
The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.
Layouts
describe in xml how the various
activities
in your app appear on screen.







Reuse parts of pages with
fragments
.

Menus
are also described in xml.
dimens.xml

allows you to name sizes of things. Best practice is to use
sp
(scale independent pixels) for font sizes,
dp
(density independent pixels) for everything else.

strings.xml
allows you to name string resources

styles.xml
allows you to define sets of styling to be applied to screen elements.
Styles
can be inherited.
Directory suffixes allow you to override view elements for different devices and locales, eg
values-w820dp
for a dimens.xml for screens more than 820dp wide
values-fr
for a French version of
strings.xml
layout-land
for a landscape version of a
layout
layout-large
for a large screen version of a
layout
Gradle
is the tool used to package up your application so it can be delivered to your device.

When you make changes to your project settings (eg dependencies) through Studio, those settings are saved in the
Gradle
files as well as in the
Studio project files (.idea and .iml files).

Gradle
files should be checked in to source control, project files should not.
The
Manifest
configures the app as a whole, and each
Activity
within it.

All
Activities
must be listed in the
Manifest
The
build
directory holds generated files including
R
, a class that provides references to all resources.
src/main/java
holds your Java classes. Android Studio creates the first one for you. It's an
Activity
.
Activities
are descendants of
android.app.Activity
. They are
controllers
that orchestrate the flow of control between screens of your app. Keep the code in these as brief as possible. Business logic should be delegated to
model
classes.

Use
Intents
to progress from one
Activity
to another.
An
Intent
is a description of an action to be performed, together with data relevant to the action.
Exercise 2: Create a Second Activity
Use
File > New > Activity
to open the
New Activity
wizard
. Choose
Blank Activity
on the first page. Fill in the second page like this:
Exercise 3: Capture the Player's Name
Add a
TextView
to the layout for
HelloAndroid
, where we'll display a welcome message that includes the player's name. This is NOT best practice. The
TextView
should be in the
Fragment
. We'll cover that in a later week.

Add a new Java class called '
Game
' in a new package called
com.<your package name>.androidbootcamp.model
.
Add a String field '
player
' with a getter and a constructor that takes the player's name as a parameter.

Add a field to the
HelloAndroid

Activity
of type
Game
. This will hold all the state for the current game, including the player's name.

In the
onCreate
of
HelloAndroid
, open the new activity using
startActivityForResult
.

Add an
onActivityResult
handler to
HelloAndroid
that retrieves the name from the
Intent
returned by
WhoAmI
, and uses it to create a new
Game
instance.
Exercise 4: Keep the game state safe
What happens if you switch from portrait to landscape?

To stop the game state from being lost when the activity is recreated, we have to save and restore the instance state.
Make the
Game
class implement
Serializable
(for good performance this should be
Parcelable
instead, but that adds complexity)
Use
outState.putSerializable
to save the game in the
onSaveInstanceState
method
In
onRestoreInstanceState
:
Use
savedInstanceState.getSerializable
to restore the game
Restore the text of the
Welcome

TextView

Optional extras:
Add debug logging to the
lifecycle
events of the
WhoAmI
activity to explore how the lifecycles interact.
What happens if you click the
Home
key then re-open the application. What if you click the
Back
key?
Explore the files that are created. Try running the app. Fix the compile errors.
We will use the new activity to allow the player to enter their name and return it to the first activity:
In the layout for the new activity, add a
TextView
, an
EditText
and a
Button
.
Add an
onClick
handler to the button that returns the name entered by the player
https://github.com/ThoughtWorksAustralia/AndroidBootcampProject#week-1-hello-android
Full transcript