Your SlideShare is downloading. ×
  • Like
Developing Applications for Android - Lecture#3
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Developing Applications for Android - Lecture#3

  • 854 views
Published

3rd Lecture on Developing Applications for Android.

3rd Lecture on Developing Applications for Android.

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to like this
No Downloads

Views

Total Views
854
On SlideShare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
69
Comments
1
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Developing Applications for Android Muhammad Usman Chaudhry SZABIST CS4615 Lecture # 3
  • 2. Today ● Setting up your development Environment ○ Eclipse ○ Android SDK ○ Android Development Tools (ADT) ● Creating HelloWorld Application ● File Structure ○ AndroidManifest.xml, src, assets, res, bin, gen, etc. ● Activity Lifecycle ○ onCreate, onStart, onRestart, onResume, onPause, onStop, onDestroy ● A program to study Lifecycle behavior.Muhammad Usman Chaudhry CS4615 SZABIST
  • 3. Today ● Android Virtual Devices (AVD) ○ Creating & Launching Virtual Devices/Emulator ● Running applications on Real Device ● Debugging ○ DDMS ○ adb ○ Normal debugging ○ Using LogCat ● Basics About ○ View, Fragment, Intent, Content Provider, Service ● Learning about VCS, DVCS, Git & Hg. ● Using Hg/Bitbucket as version control & how-to, clone, pull, commit and push code changes.Muhammad Usman Chaudhry CS4615 SZABIST
  • 4. Setting Up IDE ● Download Eclipse (http://eclipse.org/downloads - Eclipse Classic 4.2) ● Download & Installing Android SDK (http://developer. android.com/sdk) ● Configuring Platform APIs (Via SDK Manager) ● Installing ADT Plugin (https://dl-ssl.google. com/android/eclipse)Muhammad Usman Chaudhry CS4615 SZABIST
  • 5. Hello World Android ● Lets 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. ○ Lets 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. Lets 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. Lets 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() ● Lets have a look at code in Eclipse and view the diagram in next slide.Muhammad Usman Chaudhry CS4615 SZABIST
  • 11. Android Activity LifecycleMuhammad Usman Chaudhry CS4615 SZABIST
  • 12. Activity Lifecycle ● Lets implement the activity lifecycle on Eclipse.Muhammad Usman Chaudhry CS4615 SZABIST
  • 13. Creating and Managing AVDs● Lets create AVDs and run our application on Virtual Device.Muhammad Usman Chaudhry CS4615 SZABIST
  • 14. Running on Real Device● Running our application● Enabling debugging supportMuhammad Usman Chaudhry CS4615 SZABIST
  • 15. Debugging● Try-It-On-Eclipse: ○ Normal Debugging ○ Logcat ○ DDMS ○ adbMuhammad Usman Chaudhry CS4615 SZABIST
  • 16. Lets Discuss About ● View ● Fragment ● Intent ● Content Provider ● ServiceMuhammad 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 well study it later. ● Fragments are more targeted towards tablet applications. ● Lets have a look at its design philosophy.Muhammad Usman Chaudhry CS4615 SZABIST
  • 19. FragmentMuhammad 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. ● Lets have a look at intent.Muhammad Usman Chaudhry CS4615 SZABIST
  • 21. Content Provider ● Standard mechanism to share data among applications. ● It doesnt 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 RemoteMuhammad Usman Chaudhry CS4615 SZABIST
  • 23. Whats Version Control & Why We Need It? ● Version control is the management of changes to the source files. ● Its 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. ● Lets 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 ● Lets 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 eventsMuhammad 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! ● Well learn to use all the controls.Muhammad Usman Chaudhry CS4615 SZABIST