5. Hello World Android
● Let's create and discuss HelloWorld
Application.
Muhammad Usman Chaudhry CS4615 SZABIST
6. File Structure
● AndroidManifest.xml:
○ This file manages, Icons, Labels,
Permissions, Libraries, Intent Filters and
many other configuration parameters
related to application.
○ Let's have a look and discuss basics of
Manifest file in Eclipse.
● src:
○ Contains all the source packages, activity
and non-activity Java class files.
Muhammad Usman Chaudhry CS4615 SZABIST
7. File Structure
● assets:
○ Used to store raw data.
○ Example would be textures, game data,
static html/xml/json files etc.
○ Can access via AssetManager
● libs: Contain private libraries.
● bin: Contain compiled resources. (APK etc.)
● gen: Generated Java files. (R.java etc.)
● jni: Native code sources, developed using NDK.
Muhammad Usman Chaudhry CS4615 SZABIST
8. File Structure
● res:
○ Contain all application resources
○ Include most of the following directories:
■ anim - for xml files that are compiled
into Animation objects.
■ color - for xml files that describe colors.
■ drawable - for images, drawable
resource types like BMP,JPG, 9-patch
etc. Let's discuss more about drawable
over Eclipse.
Muhammad Usman Chaudhry CS4615 SZABIST
9. File Structure
■ layout - XML files compiled into screen
objects/views.
■ menu - XML files defining application
menus.
■ raw - Same as assets, except it can be
accessed via R file.
■ values - XML files containing string
values. Let's see how its used.
■ xml - Other xml files, eg.
PreferenceScreen, etc.
Muhammad Usman Chaudhry CS4615 SZABIST
10. Android Activity Lifecycle
● Activity instances in our apps transition between various
states whenever a user interacts with the application.
● Mostly these events are called in following order:
○ onCreate(Bundle savedInstanceState)
○ onStart()
○ onResume()
○ onPause()
○ onRestart()
○ onStop()
○ onDestroy()
● Let's have a look at code in Eclipse and view the diagram
in next slide.
Muhammad Usman Chaudhry CS4615 SZABIST
16. Let's Discuss About
● View
● Fragment
● Intent
● Content Provider
● Service
Muhammad Usman Chaudhry CS4615 SZABIST
17. View
● View represents the basic building block for UI components.
● All the controls within android are direct or indirect
subclasses of View.
● We may extend View or even its subclasses to create
custom controls.
● Examples are:
○ Direct Subclasses:
■ ImageView
■ TextView
■ And many other...
○ Indirect Subclasses:
■ Button
■ ListView
■ And many more...
Muhammad Usman Chaudhry CS4615 SZABIST
18. Fragment
● A fragment represents a behavior or a
portion of user interface in an activity.
● You may combine multiple fragments in a
single activity to build a multi-pane UI.
● Fragment have lifecycle of its own, but
we'll study it later.
● Fragments are more targeted towards
tablet applications.
● Let's have a look at its design philosophy.
Muhammad Usman Chaudhry CS4615 SZABIST
20. Intent
● More like an 'intention' to do some work.
● Intents are used to:
○ Broadcast a message
○ Start a service
○ Launch an activity
○ Display a web page
○ Dial a phone number
● Intents can be explicit or implicit.
● Let's have a look at intent.
Muhammad Usman Chaudhry CS4615 SZABIST
21. Content Provider
● Standard mechanism to share data among
applications.
● It doesn't expose underlying storage,
structure and implementation.
● Your application can expose data to other
applications or even read the data shared
by other applications.
Muhammad Usman Chaudhry CS4615 SZABIST
22. Service
● Background processes that runs for long
time.
● Android has 2 type of services:
○ Local Services:
■ Only used by the application that is hosting it.
○ Remote Services:
■ Accessible by other applications as well.
● Local Vs Remote
Muhammad Usman Chaudhry CS4615 SZABIST
23. What's Version Control & Why We Need It?
● Version control is the management of
changes to the source files.
● It's used to keep track of who did what and
when in the code.
● In case of problem in latest code, you can
easily revert back to any past version.
● Easier to collaborate and track the code
changes among programmers working on
the same project and files.
Muhammad Usman Chaudhry CS4615 SZABIST
24. Standard Version Control System
● Usually a central server.
● A programmer may check-out a file, work
over it and checks-in back.
● When a programmer has checked the file
out, no other programmers can make
changes to that particular file.
● Famous framework is SVN, CVS etc.
Muhammad Usman Chaudhry CS4615 SZABIST
25. DVCS
Distributed Version Control System
● Instead of centralized system it uses P2P.
● Avoids single point of failure.
● Allow users to check-in and merge the code
anytime they want to.
● Famous frameworks are Hg(Mercurial) and
Git.
● Let's watch this video to get more detailed
idea:
○ http://www.fogcreek.com/kiln/
Muhammad Usman Chaudhry CS4615 SZABIST
26. Mercurial & Git
● Mercurial (Hg) & Git are 2 leading
frameworks used for Revision Control.
● Basic difference is,
○ git provide set of tools like git-pull, git-push, etc.
○ Hg is monolithic and all in one.
● Both have almost identical features.
● We prefer Mercurial, due to easier learning
curve.
Muhammad Usman Chaudhry CS4615 SZABIST
27. Using Hg & BB
● Installing Hg
● Let's create a repository at Bitbucket (BB) Source
code hosting site.
● Create a local repository. (hg init)
● Add Files. (hg add .)
● Commit changes (hg commit -m "first")
● Push our changes to BB. (hg push REPO-URL)
● Remember repeat cycle
○ Pull - Update - Merge/Resolve - Commit - Push
● Adding users to BB & using (hg clone to get current
copy).
● We shall look into branching etc. later.
Muhammad Usman Chaudhry CS4615 SZABIST
28. Lab Tasks Today
● Setup Android Development Environment
● Create HelloWorld Application
● Create AVDs
● Run your application in at least 2 different
AVDs
● Create Lifecycle Activity Application
● Log all lifecycle events
Muhammad Usman Chaudhry CS4615 SZABIST
29. Lab Tasks Today
● Setup Hg on System, create Bitbucket account.
● Create a group of 2, invite your partner so he/she
could clone the code, make changes and pass
through the following Steps:
○ init-add-commit-push (For you)
○ clone (For other group partner)
○ //Make certain changes
○ pull-update-commit-push (For other group
partner)
○ //Make certain changes
○ pull-update-commit-push (For you)
Muhammad Usman Chaudhry CS4615 SZABIST
30. Coming Up Next
● Detail in Design!
● We'll learn to use all the controls.
Muhammad Usman Chaudhry CS4615 SZABIST