Android 101 Session @thejunction32

757 views

Published on

Android engineering 101,

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
757
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Android 101 Session @thejunction32

  1. 1. Android 101<br />נושאיההרצאה:<br /><ul><li>מהזה ?Android
  2. 2. מהםכליהעבודה?
  3. 3. מהםאבניהבנייןשליישום ? Android
  4. 4. איזהכליםישבשביל? Debugging </li></li></ul><li>What’s Android?<br />An open source mobile operating system.<br />Linux kernel base.<br />Inc. open source.<br />Custom Application<br />Framework layer.<br />
  5. 5. What’s given by Android for development?<br />ADB.<br />AVD manager and emulator.<br />Android devices.<br />SDK.<br />NDK.<br />Android tools.<br />
  6. 6. The “Android Debug Bridge” is: <br />A command line tool.<br />handles communication with a development unit<br />a client-server program that includes three components:<br />A client, which runs on your computer. <br />A server, which runs as a background process.<br />A daemon, which runs as a background process on each development unit.<br />Android tools – ADB.<br />
  7. 7. Runs on your computer.<br />Mouse/keyboard to mimic touch and key events.<br />Mimics all hardware and software features.<br />Different screen sizes and densities.<br />Emulating phone events (SMS, phone calls).<br />Spoofing location events.<br />Different API levels.<br />Android tools – Emulator.<br />
  8. 8. Android tools – Emulator.<br />
  9. 9. All android devices are debug-able via USB “out of the box” (no root is needed).<br />To enable:<br />Settings>applications:<br />Allow unknown resources.<br />Settings>applications>development:<br />Allow USB debugging.<br />Stay awake.<br />Android tools – Device.<br />
  10. 10. Programming language: JAVA + XML.<br />Create standard android application by using and utilizing the applications framework.<br />Most popularIDE:<br />Eclipse + ADT.<br />Other possible IDEs:<br />intellij.<br />Net beans.<br />Android tools – SDK.<br />
  11. 11. Programming language: everything!<br />Create an android application by accessing the native code directly.<br />Reasons for using NDK:<br />Using non-java ready made code.<br />Using hardware acceleration.<br />A real need for more <br />performance.<br />Android tools – NDK.<br />
  12. 12. Android building blocks<br />The components of an android application and their connecting methods.<br />
  13. 13. The (Android) application.<br />An application consists of<br />A manifest xml.<br />A set of:<br />Activities.<br />Services.<br />Broadcast receivers.<br />Content providers.<br />
  14. 14. The Manifest<br />The Manifest is essentially a list of components that the application uses or requires, such as:<br />The components of the applications.<br />User permissions .<br />The minimum API level.<br />Hardware and software features.<br />API dependencies.<br />
  15. 15. A manifest example<br />
  16. 16. .The Activity<br />An activity represents a single screen with a user interface (Java file + xml layout file).<br />An application usually consists of multiple activities that are loosely bound to each other.<br />One Activity is flagged as “main” and it is started at the application launch time.<br />An Activity can launch other activities to create an app UI workflow. <br />The Activity has an Intent attribute that determines how android treats it.<br />
  17. 17. Activity explained with an example.<br />A screen that displays a list of emails.<br />A screen that displays a single email.<br />A screen <br />that enables you <br />to compose <br />an email.<br />Each and every one of these is an Activity!<br />
  18. 18. Starting an Activity.<br />When you press reply:<br /><ul><li>The compose Activity gets called.
  19. 19. The recipients aresent via the</li></ul>“Extras” attribute of the intent.<br />
  20. 20. The Activity life-cycle.<br />There are 6 stages in the Android Activity life cycle.<br />These stages allow you to perform tasks in their correct time of the workflow.<br />
  21. 21. The Activity life-cycle vol2.<br />
  22. 22. SharedPrefs – A tool that saves data to a file so it will be available even if the app is closed and restarted.<br />It is generally used for:<br />1. Saving user preferences.<br />2. Saving a “snapshot” of the app so it could be resumed to precisely the same state. <br />The Activity life-cycle vol3 – before example.<br />
  23. 23. The Activity life-cycle vol3 – example of use.<br />
  24. 24. Consists of xml.<br />Describe the static layout of a screen.<br />A few types available:<br />LinearLayout– children are lined up automatically.<br />RelativeLayout- children order needs to be defined.<br />ListView– children are items of a list.<br />Etc.<br />The Activity – Layout.<br />
  25. 25. The Activity – Layout example.<br />
  26. 26. .The Service<br />An application component that can perform long-running operations in the background and does not provide a user interface.<br />The service has two forms:<br /><ul><li>A "started“ service is called by an app component and runs in the background even if the application that called it was closed.
  27. 27. A “bound” service is bound by an app component and is used as a client-server bridge, this sort of service is terminated when the application that is bound to it is closed.</li></li></ul><li>Starting a service.<br />From the activity perform:<br />The startService() method returns immediately.<br />If the service is not already running, the android system calls onCreate(), then calls onStartCommand()else it only calls the onStartCommand() method.<br />
  28. 28. The same principle as in the activity life cycle applies here only the stages are different.<br />As you can see the bound and started services have a similar cycle with a twist:<br />The bound service is only “alive” while the binding application is “alive”.<br />The service life cycle.<br />
  29. 29. The service life cycle.<br />
  30. 30. a component that responds to system-wide broadcast announcements.<br />The announcement can originate either from a system event (screen on/off) or a custom activity event.<br />When this protocol is customized it facilitates message sending between applications and activities that should work together.<br />The Broadcast receivers.<br />
  31. 31. The manifest tag:<br />The Broadcast receivers - example.<br />
  32. 32. The broadcast receiver file:<br />The Broadcast receivers - example.<br />
  33. 33. Components that manage a shared set of application data. <br />The data is stored at one of the following formats:<br />In the file system.<br />In an SQLite database.<br />on the web.<br />More..<br />Essentially you can store it in any persistent storage location your application can access. <br />The Content providers.<br />
  34. 34. Through the content provider, other applications can query or even modify the data (if the content provider allows it). <br />providers are also useful for reading and writing data that is private to your application and is not shared.<br />The Content providers.<br />
  35. 35. Here’s a few examples for system content providers:<br />Contacts.<br />Text messages.<br />Phone calls.<br />The Content providers – examples.<br />
  36. 36. Android provides a few precious tools for that:<br />DDMS.<br />Logcat.<br />Hierarchy viewer.<br />Monkey & monkey runner.<br />Android debug tools.<br />
  37. 37. Android debug tools – DDMS.<br />The “DalvikDebug Monitor Server (DDMS)” is: <br />A debugging tool that provides:<br />Port forwarding services. <br />Screen capture.<br /> thread and heap information.<br /> Logcatand process logging.<br />Mobile data spoofing (location, calls and SMS)<br />Memory dump.<br />
  38. 38. Android debug tools – DDMS.<br />
  39. 39. Amechanism for collecting and viewing system debug output.<br />Filter levels:<br />V — Verbose (lowest priority)<br />D — Debug<br />I — Info<br />W — Warning<br />E — Error<br />Invoke logs with a custom TAG in your app to monitor its operation:<br />Android debug tools – Logcat.<br />
  40. 40.  Displays the View objects that form the UI of the Activity that is running on your device or emulator. <br />Start command: <sdk>/tools/hierarchyviewer<br />If #levels > 7 -> NOT GOOD!<br />Android debug tools – Hierarchy viewer.<br />
  41. 41. Creates random UI events.<br />Great UI durability test.<br />You can configure:<br />The amount of event.<br />Percentage of touch/motion/track/key events.<br />The monkey’s “aggressiveness” (die after exception/error/security error etc.).<br />Android debug tools – Monkey.<br />
  42. 42. Enables using the monkey tool in a more precise way:<br />Write a python code.<br />The monkey performs it.<br />Great for recreating bugs and create tests to see when they are resolved.<br />Android debug tools – Monkey runner.<br />
  43. 43. Tips and pointers - ANR.<br />“Activity not responding”:<br />Appears if:<br />5 seconds of no action after a touch event.<br />10 second after invoking a BR it hasn’t finished working.<br />Why?<br />Every activity has 1 UI thread and if it is stuck the UX suffers.<br />
  44. 44. Everything that isn’t a UI action shouldn’t be on the UI thread, use:<br />AsyncTask.<br />TimerTask.<br />Handler.<br />Scheduled task.<br />Thread.<br />Then post your data on the UI thread.<br />Tips and pointers – Avoid ANR.<br />
  45. 45. Create an AsyncTask:<br />start an AsyncTask:<br />Tips and pointers – example.<br />
  46. 46. Many different devices = Many different screen sizes.<br />Prepare by:<br />Use wrap_content, fill_parent, or dp units for layouts (no PX reframe from hardcoded values altogether).<br />Test on many different Emulator instances.<br />Use 9patch images (they stretch correctly). <br /><ul><li>Add per-resolution drawable resource folder:
  47. 47. -  layout-small/…
  48. 48. - layout-xlarge/..</li></ul>Tips and pointers – Multiple screens.<br />
  49. 49. 3 main possibilities:<br />GPS.<br />Most accurate.<br />Wireless networks.<br />Gives faster results.<br />Costs less battery.<br />Works inside buildings.<br />Cell towers.<br />Always available.<br />Tips and pointers – location detection.<br />

×