• Like
Android ppt
Upcoming SlideShare
Loading in...5
×

Android ppt

  • 1,312 views
Uploaded on

Android PowerPoint PPT

Android PowerPoint PPT

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,312
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
104
Comments
0
Likes
1

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
  • named after a robot in Bladerunner
  • The linux kernel 2.6 is the hardware abstraction layer (HAL) between the hardware and the android software stack.
  • Maybe more profitable with ads than actually selling the app

Transcript

  • 1. BASICS OF MOBILE O/S
  • 2. A MOBILE OPERATING SYSTEM • A MOBILE OPERATING SYSTEM, ALSO REFERRED TO AS MOBILE OS, IS AN OPERATING SYSTEM THAT OPERATES A SMARTPHONE, TABLET, PDA, OR OTHER MOBILE DEVICE. MODERN MOBILE OPERATING SYSTEMS COMBINE THE FEATURES OF A PERSONAL COMPUTER OPERATING SYSTEM WITH OTHER FEATURES, INCLUDING A TOUCHSCREEN, CELLULAR, BLUETOOTH, WI-FI, GPS MOBILE NAVIGATION, CAMERA, VIDEO CAMERA, SPEECH RECOGNITION, VOICE RECORDER, MUSIC PLAYER, NEAR FIELD COMMUNICATION AND INFRARED BLASTER. • MOBILE DEVICES WITH MOBILE COMMUNICATIONS CAPABILITIES (E.G. SMARTPHONES) CONTAIN TWO MOBILE OPERATING SYSTEMS - THE MAIN USER-FACING SOFTWARE PLATFORM IS SUPPLEMENTED BY A SECOND LOW-LEVEL PROPRIETARY REAL-TIME OPERATING SYSTEM WHICH OPERATES THE RADIO AND OTHER HARDWARE. RESEARCH HAS SHOWN THAT THESE LOW-LEVEL SYSTEMS MAY CONTAIN A RANGE OF SECURITY VULNERABILITIES PERMITTING MALICIOUS BASE STATIONS TO GAIN HIGH LEVELS OF CONTROL OVER THE MOBILE DEVICE.
  • 3. • BLACKBERRY • IT IS CLOSED SOURCE AND PROPRIETARY. BLACKBERRY 10 (PREVIOUSLY BLACKBERRY BBX) WAS THE NEXT GENERATION PLATFORM FOR BLACKBERRY SMARTPHONES AND TABLETS. ONE OS WAS PLANNED FOR BOTH BLACKBERRY SMARTPHONES AND TABLETS GOING FORWARD •IOS • IOS IS FROM APPLE INC. IT IS CLOSED SOURCE AND PROPRIETARY AND BUILT ON OPEN SOURCE DARWIN CORE OS. THE APPLE IPHONE, IPOD TOUCH, IPAD AND SECOND-GENERATION APPLE.
  • 4. • WINDOWS PHONE • WINDOWS PHONE IS FROM MICROSOFT. IT IS CLOSED SOURCE AND PROPRIETARY. ON FEBRUARY 15, 2010, MICROSOFT UNVEILED ITS NEXT-GENERATION MOBILE OS, WINDOWS PHONE. THE NEW MOBILE OS INCLUDES A COMPLETELY NEW OVERHAULED UI INSPIRED BY MICROSOFT'S "METRO DESIGN LANGUAGE". IT INCLUDES FULL INTEGRATION OF MICROSOFT SERVICES SUCH AS MICROSOFT SKYDRIVE AND OFFICE, XBOX MUSIC, XBOX VIDEO, XBOX LIVE GAMES AND BING, BUT ALSO INTEGRATES WITH MANY OTHER NON-MICROSOFT SERVICES SUCH AS FACEBOOK AND GOOGLE ACCOUNTS. WINDOWS PHONE DEVICES ARE MADE PRIMARILY BY NOKIA, ALONG WITH HTC, SAMSUNG, HUAWEI AND OTHER. OEMS. (ORIGINAL EQUIPMENT MANUFACTURER)
  • 5. J2ME
  • 6. ANDROID O/S • ANDROID IS AN OPERATING SYSTEM BASED ON THE LINUX KERNEL AND DESIGNED PRIMARILY FOR TOUCHSCREEN MOBILE DEVICES SUCH AS SMARTPHONES AND TABLET COMPUTERS. INITIALLY DEVELOPED BY ANDROID, INC., WHICH GOOGLE BACKED FINANCIALLY AND LATER BOUGHT IN 2005, ANDROID WAS UNVEILED IN 2007 ALONG WITH THE FOUNDING OF THE OPEN HANDSET ALLIANCE: A CONSORTIUM OF HARDWARE, SOFTWARE, AND TELECOMMUNICATION COMPANIES DEVOTED TO ADVANCING OPEN STANDARDS FOR MOBILE DEVICES. THE FIRST PUBLICLY AVAILABLE SMARTPHONE RUNNING ANDROID, THE HTC DREAM, WAS RELEASED ON OCTOBER 22, 2008
  • 7. • ANDROID'S SOURCE CODE IS RELEASED BY GOOGLE UNDER THE APACHE LICENSE; • AS OF JULY 2013, ANDROID HAS THE LARGEST NUMBER OF APPLICATIONS ("APPS"), AVAILABLE FOR DOWNLOAD IN GOOGLE PLAY STORE WHICH HAS HAD OVER 1 MILLION APPS PUBLISHED, AND OVER 50 BILLION DOWNLOADS. • A DEVELOPER SURVEY CONDUCTED IN APRIL–MAY 2013 FOUND THAT ANDROID IS THE MOST USED PLATFORM AMONG DEVELOPERS: IT IS USED BY 71% OF THE MOBILE DEVELOPERS POPULATION
  • 8. OHA • THE OPEN HANDSET ALLIANCE (OHA) IS A CONSORTIUM OF 84 FIRMS TO DEVELOP OPEN STANDARDS FOR MOBILE DEVICES. MEMBER FIRMS INCLUDE GOOGLE, HTC, SONY, DELL, INTEL, MOTOROLA, QUALCOMM, TEXAS INSTRUMENTS, SAMSUNG ELECTRONICS, LG ELECTRONICS, T-MOBILE, SPRINT CORPORATION, NVIDIA, AND WIND RIVER SYSTEMS. • THE OHA WAS ESTABLISHED ON 6 NOVEMBER 2007, LED BY GOOGLE WITH 34 MEMBERS INCLUDING MOBILE HANDSET MAKERS, APPLICATION DEVELOPERS, SOME MOBILE CARRIERS AND CHIP MAKERS. • ANDROID, THE FLAGSHIP SOFTWARE OF THE ALLIANCE, IS BASED ON AN OPEN SOURCE LICENSE AND HAS COMPETED AGAINST MOBILE PLATFORMS FROM APPLE, MICROSOFT, NOKIA (SYMBIAN), HP (FORMERLY PALM), SAMSUNG ELECTRONICS / INTEL (TIZEN, BADA), AND BLACKBERRY. • AS PART OF ITS EFFORTS TO PROMOTE A UNIFIED ANDROID PLATFORM, OHA MEMBERS ARE CONTRACTUALLY FORBIDDEN FROM PRODUCING DEVICES THAT ARE BASED OFF INCOMPATIBLE FORKS OF ANDROID
  • 9. GALAXY TABLET
  • 10. ANDROID-POWERED MICROWAVE By Touch Revolution – at CES 2010 http://www.pocket-lint.com/news/30712/android-powered-microwave-cookinggoogle
  • 11. ANDROID-POWERED WATCH
  • 12. ANDROID-POWERED CAMERA
  • 13. ANDROID-POWERED TV
  • 14. ANDROID-POWERED CAR RADIO
  • 15. ANDROID-POWERED WASHING MACHINE
  • 16. ANDROID-POWERED PC
  • 17. ANDROID TV
  • 18. ANDROID VERSIONS Honeycomb Android 3.0-3.2 Ice cream Sandwich Jelly Bean KitKat Android 4.0+ Android 4.1.1 Android 4.4
  • 19. DIFFERENT ANDROID VERSIONS
  • 20. DISTRIBUTION OF DEVICES DATA COLLECTED DURING A 14-DAY PERIOD ENDING ON JANUARY 3, 2012 HTTP://DEVELOPER.ANDROID.COM/RESOURCES/DASHBOARD/PLATFORM-VERSIONS.HTML
  • 21. DISTRIBUTION OF DEVICES HTTP://DEVELOPER.ANDROID.COM/RESOURCES/DASHBOARD/PLATFORM-VERSIONS.HTML
  • 22. WHAT IS GOOGLE ANDROID? • A SOFTWARE STACK FOR MOBILE DEVICES THAT INCLUDES • AN OPERATING SYSTEM • MIDDLEWARE • KEY APPLICATIONS • USES LINUX TO PROVIDE CORE SYSTEM SERVICES • • • • • SECURITY MEMORY MANAGEMENT PROCESS MANAGEMENT POWER MANAGEMENT HARDWARE DRIVERS
  • 23. ANDROID ARCHITECTURE
  • 24. MOBILE DEVICES: ADVANTAGES • ALWAYS WITH THE USER • TYPICALLY HAVE INTERNET ACCESS • TYPICALLY GPS ENABLED • TYPICALLY HAVE ACCELEROMETER & COMPASS • MOST HAVE CAMERAS & MICROPHONES • MANY APPS ARE FREE OR LOW-COST
  • 25. MOBILE DEVICES: DISADVANTAGES • • • • LIMITED SCREEN SIZE LIMITED BATTERY LIFE LIMITED PROCESSOR SPEED LIMITED AND SOMETIMES SLOW NETWORK ACCESS • LIMITED OR AWKWARD INPUT: SOFT KEYBOARD, PHONE KEYPAD, TOUCH SCREEN, OR STYLUS • LIMITED WEB BROWSER FUNCTIONALITY • RANGE OF PLATFORMS & CONFIGURATIONS ACROSS DEVICES
  • 26. MOBILE APPLICATIONS • WHAT ARE THEY? • ANY APPLICATION THAT RUNS ON A MOBILE DEVICE • TYPES • WEB APPS: RUN IN A WEB BROWSER • HTML, JAVASCRIPT, FLASH, SERVER-SIDE COMPONENTS, ETC. • NATIVE: COMPILED BINARIES FOR THE DEVICE • OFTEN MAKE USE OF WEB SERVICES
  • 27. ANDROID APPS • BUILT USING JAVA AND NEW SDK LIBRARIES • NO SUPPORT FOR SOME JAVA LIBRARIES LIKE SWING & AWT • JAVA CODE COMPILED INTO DALVIK BYTE CODE (.DEX) • OPTIMIZED FOR MOBILE DEVICES (BETTER MEMORY MANAGEMENT, BATTERY UTILIZATION, ETC.) • DALVIK VM RUNS .DEX FILES
  • 28. • DEVELOPMENT PROCESS FOR AN ANDROID APP http://developer.android.com/guide/developing/index.html
  • 29. ANDROID DESIGN PHILOSOPHY • APPLICATIONS SHOULD BE: • FAST • RESOURCE CONSTRAINTS: <200MB RAM, SLOW PROCESSOR • RESPONSIVE • APPS MUST RESPOND TO USER ACTIONS WITHIN 5 SECONDS • SECURE • APPS DECLARE PERMISSIONS IN MANIFEST • SEAMLESS • USABILITY IS KEY, PERSIST DATA, SUSPEND SERVICES • ANDROID KILLS PROCESSES IN BACKGROUND AS NEEDED
  • 30. BUILDING AND RUNNING Compiled resources (xml files) Android Debug Bridge • ADB IS A CLIENT SERVER PROGRAM THAT CONNECTS CLIENTS ON DEVELOPER MACHINE TO DEVICES/EMULATORS TO FACILITATE DEVELOPMENT. • AN IDE LIKE ECLIPSE HANDLES THIS ENTIRE PROCESS FOR YOU. http://developer.android.com/guide/developing/building/index.html#detailed-build
  • 31. BUILDING AND RUNNING
  • 32. APPLICATIONS ARE BOXED • BY DEFAULT, EACH APP IS RUN IN ITS OWN LINUX PROCESS • PROCESS STARTED WHEN APP’S CODE NEEDS TO BE EXECUTED • THREADS CAN BE STARTED TO HANDLE TIMECONSUMING OPERATIONS • EACH PROCESS HAS ITS OWN DALVIK VM • BY DEFAULT, EACH APP IS ASSIGNED UNIQUE LINUX ID • PERMISSIONS ARE SET SO APP’S FILES ARE ONLY VISIBLE TO THAT APP
  • 33. ANDROID RCHITECTURE
  • 34. PUBLISHING AND MONETIZING • PAID APPS IN ANDROID MARKET, VARIOUS OTHER MARKETS • FREE, AD-SUPPORTED APPS IN ANDROID MARKET • AD NETWORKS (GOOGLE ADMOB, QUATTRO WIRELESS) • SELL YOUR OWN ADS • SERVICES TO OTHER DEVELOPERS • CONTESTS (ANDROID DEVELOPER CHALLENGE) • SELLING PRODUCTS FROM WITHIN YOUR APP
  • 35. ADNROID O/S FILE SYSTEM
  • 36. THE ANDROID OS – 2. FILE SYSTEM  SUPPORTED BY YAFFS2 FILE SYSTEM.  YAFFS: YET ANOTHER FLASH FILE SYSTEM  YAFFS1: DESIGNED FOR OLD NAND CHIPS WITH 512 BYTE PAGES PLUS 16 BYTE SPARE AREAS.  YAFFS2: EVOLVED FROM YAFFS1 TO ACCOMMODATE NEWER CHIPS WITH 2048 BYTE PAGES PLUS 64 BYTES SPARE AREAS.
  • 37. YAFFS2 • YAFFS (YET ANOTHER FLASH FILE SYSTEM) IS AN OPENSOURCE FILE SYSTEM SPECIFICALLY DESIGNED TO BE FAST, ROBUST AND SUITABLE FOR EMBEDDED USE WITH NAND AND NOR FLASH. IT IS WIDELY USED WITH LINUX, RTOSS (A REAL-TIME OPERATING SYSTEM) AT ALL, IN CONSUMER DEVICES. IT IS AVAILABLE UNDER GNU PUBLIC LICENSE, GPL, OR ON COMMERCIAL TERMS FROM ALEPH ONE.
  • 38. ANDROID SDK MOBILE DEVICE EMULATOR • THE ANDROID SDK INCLUDES A MOBILE DEVICE EMULATOR — A VIRTUAL MOBILE DEVICE THAT RUNS ON YOUR COMPUTER. THE EMULATOR LETS YOU DEVELOP AND TEST ANDROID APPLICATIONS WITHOUT USING A PHYSICAL DEVICE.
  • 39. 32 bit / 64 bit • The main difference between 32-bit processors and 64-bit processors is the speed they operate. 64-bit processors can come in dual core, quad core, and six core versions for home computing (with eight core versions coming soon). • It is important to note that 64-bit computers can still use 32-bit based software programs, even when the Windows operating system is a 64bit version. • Another big difference between 32-bit processors and 64-bit processors is the maximum amount of memory (RAM) that is supported. 32-bit computers support a maximum of 3-4GB of memory, whereas a 64-bit computer can support memory amounts over 4 GB. • One thing to note is that 3D graphic programs and games do not benefit much, if at all, from switching to a 64-bit computer, unless the program is a 64-bit program. A 32-bit processor is adequate for any program written for a 32-bit processor • In the end, 64-bit processors are becoming more and more commonplace in home computers. Most manufacturers build computers with 64-bit processors due to cheaper prices and because more users are now using 64-bit operating systems and programs.
  • 40. ANDROID BASICS
  • 41. SETTING UP ANDROID DEVELOPMENT ENVIRONMENT / INSTALLING ANDROID • STEP 1 : DOWNLOAD JDK: (JAVA DEVELOPMENT KIT). FOR JAVA DEVELOPERS. INCLUDES A COMPLETE JRE PLUS TOOLS FOR DEVELOPING, DEBUGGING, AND MONITORING JAVA APPLICATIONS. • STEP 2 : • GET THE ANDROID SDK • THE ANDROID SDK PROVIDES YOU THE API LIBRARIES AND DEVELOPER TOOLS NECESSARY TO BUILD, TEST, AND DEBUG APPS FOR ANDROID. • WITH A SINGLE DOWNLOAD, THE ADT BUNDLE INCLUDES EVERYTHING YOU NEED TO BEGIN DEVELOPING APPS: • ECLIPSE + ADT PLUGIN • ANDROID SDK TOOLS • ANDROID PLATFORM-TOOLS • THE LATEST ANDROID PLATFORM • THE LATEST ANDROID SYSTEM IMAGE FOR THE EMULATOR • STEP 3 AFTER INSTALL THE APPLICATION YOU NEED TO SPECIFY THE PACKAGES, THAT WHICH API VERSION YOU NEED.
  • 42. ANDROID SDK • ONCE INSTALLED OPEN THE SDK MANAGER • INSTALL THE DESIRED PACKAGES • CREATE AN ANDROID VIRTUAL DEVICE (AVD)
  • 43. SDK MANAGER
  • 44. AVD
  • 45. ADT PLUGIN (1) • IN ECLIPSE, GO TO HELP -> INSTALL NEW SOFTWARE • CLICK ‗ADD‘ IN TOP RIGHT • ENTER: • NAME: ADT PLUGIN • LOCATION: HTTPS://DL-SSL.GOOGLE.COM/ANDROID/ECLIPSE/ • CLICK OK, THEN SELECT ‗DEVELOPER TOOLS‘, CLICK NEXT • CLICK NEXT AND THEN FINISH • AFTERWARDS, RESTART ECLIPSE • SPECIFY SDK LOCATION (NEXT 3 SLIDES) • MUST DO THIS EVERY TIME START A NEW PROJECT IN A NEW LOCATION (AT LEAST IN WINDOWS)
  • 46. ADT PLUGIN (2)
  • 47. ADT PLUGIN (3)
  • 48. ADT PLUGIN (4)
  • 49. CREATING A PROJECT (1)
  • 50. NEED THE ITEMS CIRCLED THEN CLICK FINISH CREATING A PROJECT (2)
  • 51. PROJECT COMPONENTS • SRC – YOUR SOURCE CODE • GEN – AUTO-GENERATED CODE (USUALLY JUST R.JAVA) • INCLUDED LIBRARIES • RESOURCES • DRAWABLES (LIKE .PNG IMAGES) • LAYOUTS • VALUES (LIKE STRINGS) • MANIFEST FILE
  • 52. XML • USED TO DEFINE SOME OF THE RESOURCES • LAYOUTS (UI) • STRINGS • MANIFEST FILE • SHOULDN‘T USUALLY HAVE TO EDIT IT DIRECTLY, ECLIPSE CAN DO THAT FOR YOU • PREFERRED WAY OF CREATING UIS • SEPARATES THE DESCRIPTION OF THE LAYOUT FROM ANY ACTUAL CODE THAT CONTROLS IT • CAN EASILY TAKE A UI FROM ONE PLATFORM TO ANOTHER
  • 53. R CLASS • AUTO-GENERATED: YOU SHOULDN‘T EDIT IT • CONTAINS IDS OF THE PROJECT RESOURCES • ENFORCES GOOD SOFTWARE ENGINEERING • USE FINDVIEWBYID AND RESOURCES OBJECT TO GET ACCESS TO THE RESOURCES • EX. BUTTON B = (BUTTON)FINDVIEWBYID(R.ID.BUTTON1) • EX. GETRESOURCES().GETSTRING(R.STRING.HELLO));
  • 54. LAYOUTS (1) • ECLIPSE HAS A GREAT UI CREATOR • GENERATES THE XML FOR YOU • COMPOSED OF VIEW OBJECTS • CAN BE SPECIFIED FOR PORTRAIT AND LANDSCAPE MODE • USE SAME FILE NAME, SO CAN MAKE COMPLETELY DIFFERENT UIS FOR THE ORIENTATIONS WITHOUT MODIFYING ANY CODE
  • 55. LAYOUTS (2)
  • 56. LAYOUTS (3) • CLICK ‗CREATE‘ TO MAKE LAYOUT MODIFICATIONS • WHEN IN PORTRAIT MODE CAN SELECT ‗PORTRAIT‘ TO MAKE A RES SUB FOLDER FOR PORTRAIT LAYOUTS • LIKEWISE FOR LANDSCAPE LAYOUTS WHILE IN LANDSCAPE MODE • WILL CREATE FOLDERS TITLED ‗LAYOUT-PORT‘ AND ‗LAYOUT-LAND‘ • NOTE: THESE ‗PORT‘ AND ‗LAND‘ FOLDERS ARE EXAMPLES OF ‗ALTERNATE LAYOUTS‘, SEE HERE FOR MORE INFO • HTTP://DEVELOPER.ANDROID.COM/GUIDE/TOPICS/RESOURCES/PROVIDINGRESOURCES.HTML • AVOID ERRORS BY MAKING SURE COMPONENTS
  • 57. LAYOUTS (4)
  • 58. STRINGS • IN RES/VALUES • STRINGS.XML • APPLICATION WIDE AVAILABLE STRINGS • PROMOTES GOOD SOFTWARE ENGINEERING • UI COMPONENTS MADE IN THE UI EDITOR SHOULD HAVE TEXT DEFINED IN STRINGS.XML • STRINGS ARE JUST ONE KIND OF ‗VALUE‘ THERE ARE MANY OTHERS
  • 59. MANIFEST FILE (1) • CONTAINS CHARACTERISTICS ABOUT YOUR APPLICATION • WHEN HAVE MORE THAN ONE ACTIVITY IN APP, NEED TO SPECIFY IT IN MANIFEST FILE • GO TO GRAPHICAL VIEW OF THE MANIFEST FILE • ADD AN ACTIVITY IN THE BOTTOM RIGHT • BROWSE FOR THE NAME OF THE ACTIVITY • NEED TO SPECIFY SERVICES AND OTHER COMPONENTS TOO • ALSO IMPORTANT TO DEFINE PERMISSIONS AND EXTERNAL LIBRARIES, LIKE GOOGLE MAPS API
  • 60. MANIFEST FILE (2) – ADDING AN ACTIVITY
  • 61. ANDROID PROGRAMMING COMPONENTS • ACTIVITY • HTTP://DEVELOPER.ANDROID.COM/GUIDE/TOPICS/FUNDAMENTALS/ACTIV ITIES.HTML • SERVICE • HTTP://DEVELOPER.ANDROID.COM/GUIDE/TOPICS/FUNDAMENTALS/SERVI CES.HTML • CONTENT PROVIDERS • BROADCAST RECEIVERS • ANDROID IN A NUTSHELL: • HTTP://DEVELOPER.ANDROID.COM/GUIDE/TOPICS/FUNDAMENTA LS.HTML
  • 62. ACTIVITIES (1) • THE BASIS OF ANDROID APPLICATIONS • A SINGLE ACTIVITY DEFINES A SINGLE VIEWABLE SCREEN • THE ACTIONS, NOT THE LAYOUT • CAN HAVE MULTIPLE PER APPLICATION • EACH IS A SEPARATE ENTITY • THEY HAVE A STRUCTURED LIFE CYCLE • DIFFERENT EVENTS IN THEIR LIFE HAPPEN EITHER VIA THE USER TOUCHING BUTTONS OR PROGRAMMATICALLY
  • 63. ACTIVITIES (2)
  • 64. SERVICES (1) • RUN IN THE BACKGROUND • CAN CONTINUE EVEN IF ACTIVITY THAT STARTED IT DIES • SHOULD BE USED IF SOMETHING NEEDS TO BE DONE WHILE THE USER IS NOT INTERACTING WITH APPLICATION • OTHERWISE, A THREAD IS PROBABLY MORE APPLICABLE • SHOULD CREATE A NEW THREAD IN THE SERVICE TO DO WORK IN, SINCE THE SERVICE RUNS IN THE MAIN THREAD • CAN BE BOUND TO AN APPLICATION • IN WHICH CASE WILL TERMINATE WHEN ALL APPLICATIONS BOUND TO IT UNBIND • ALLOWS MULTIPLE APPLICATIONS TO COMMUNICATE WITH IT VIA A COMMON INTERFACE • NEEDS TO BE DECLARED IN MANIFEST FILE • LIKE ACTIVITIES, HAS A STRUCTURED LIFE CYCLE
  • 65. SERVICES (2)
  • 66. RUNNING IN ECLIPSE (1) • SIMILAR TO LAUNCHING A REGULAR JAVA APP, USE THE LAUNCH CONFIGURATIONS • SPECIFY AN ANDROID APPLICATION AND CREATE A NEW ONE • SPECIFY ACTIVITY TO BE RUN • CAN SELECT A MANUAL OPTION, SO EACH TIME PROGRAM IS RUN, YOU ARE ASKED WHETHER YOU WANT TO USE THE ACTUAL PHONE OR THE EMULATOR • OTHERWISE, IT SHOULD BE SMART AND USE WHICHEVER ONE IS AVAILABLE
  • 67. RUNNING IN ECLIPSE (2)
  • 68. RUNNING IN ECLIPSE (3)
  • 69. RUNNING IN ECLIPSE (4)
  • 70. USB DEBUGGING • SHOULD BE ENABLED ON PHONE TO USE DEVELOPER FEATURES • IN THE MAIN APPS SCREEN SELECT SETTINGS -> APPLICATIONS -> DEVELOPMENT -> USB DEBUGGING (IT NEEDS TO BE CHECKED)
  • 71. ANDROID DEBUG BRIDGE • USED FOR A WIDE VARIETY OF DEVELOPER TASKS • READ FROM THE LOG FILE • SHOW WHAT ANDROID DEVICES ARE AVAILABLE • INSTALL ANDROID APPLICATIONS (.APK FILES) • IN THE ‗PLATFORM-TOOLS‘ DIRECTORY OF THE MAIN ANDROID SDK DIRECTORY • RECOMMEND PUTTING THIS DIRECTORY AND THE ‗TOOLS‘ DIRECTORY ON THE SYSTEM PATH • ADB.EXE
  • 72. DEBUGGING • INSTEAD OF USING TRADITIONAL SYSTEM.OUT.PRINTLN, USE THE LOG CLASS • IMPORTED WITH ANDROID.UTIL.LOG • MULTIPLE TYPES OF OUTPUT (DEBUG, WARNING, ERROR, …) • LOG.D(<TAG>,<STRING>) • CAN BE READ USING LOGCAT. • PRINT OUT THE WHOLE LOG, WHICH AUTO-UPDATES • ADB LOGCAT • ERASE LOG • ADB LOGCAT –C • FILTER OUTPUT VIA TAGS • ADB LOGCAT <TAG>:<MSG TYPE> *:S • CAN HAVE MULTIPLE <TAG>:<MSG TYPE> FILTERS • <MSG TYPE> CORRESPONDS TO DEBUG, WARNING, ERROR, ETC. • IF USE LOG.D(), THEN <MSG TYPE> = D • REFERENCE • HTTP://DEVELOPER.ANDROID.COM/GUIDE/DEVELOPING/DEBUGGING/DEB UGGING-LOG.HTML
  • 73. ANDROID – INTERFACE AND LAYOUT L. GREWE
  • 74. INTERFACES: TWO ALTERNATIVES CODE OR XML • YOU HAVE TWO WAYS YOU CAN CREATE THE INTERFACE(S) OF YOUR APPLICATION. 1. CODE = WRITE CODE USING SDK WITH CLASSES LIKE LINEARLAYOUT, TEXTVIEW, …… 2. XML = CREATE XML FILES IN RES/LAYOUT (I.E. MAIN.XML) THAT CONTAIN ANDROID XML VIEW TAGS LIKE <LINEARLAYOUT> <TEXTVIEW>, ETC.
  • 75. OPTION: XML INTERFACE LETS LOOK AT THIS OPTION FIRST
  • 76. XML INTERFACE CREATION • GENERALLY, I WOULD SAY IF IT IS POSSIBLE, DOING XML WOULD BE BETTER AS IT MEANS A DECOUPLING OF DESIGN FROM JAVA CODE. • YOU CAN HAVE BOTH IN YOUR SYSTEM…. • LETS DISCUSS THIS FIRST.
  • 77. THE LAYOUT --- THE INTERFACE • LAYOUTS DEFINED WITH XML LOCATED IN RES/LAYOUT
  • 78. THE LAYOUT-THE INTERFACE • RES/LAYOUT/MAIN.XML = CONTAINS LAYOUT FOR INTERFACE <?XML VERSION="1.0" ENCODING="UTF-8"?> <LINEARLAYOUT XMLNS:ANDROID="HTTP://SCHEMAS.ANDROID.COM/APK/RES/ANDROID" ANDROID:ORIENTATION="VERTICAL" ANDROID:LAYOUT_WIDTH="FILL_PARENT" ANDROID:LAYOUT_HEIGHT="FILL_PARENT" > <TEXTVIEW ANDROID:LAYOUT_WIDTH="FILL_PARENT" ANDROID:LAYOUT_HEIGHT="WRAP_CONTENT" ANDROID:TEXT="@STRING/HELLO" /> </LINEARLAYOUT> THE ABOVE WILL CREATE AN INTERFACE IN VERTICAL (VERSUS PORTRAIT) MODE THAT FILLS THE PARENT BOTH IN WIDTH AND WRITE AND WRAPS AND CONTENT AS NECESSARY.
  • 79. XML INTERFACE • IT'S A TREE OF XML ELEMENTS, • INSPIRED BY WEB AUTHORING • BUILD UP UI QUICKLY • EACH NODE IS THE NAME OF A VIEW CLASS (EXAMPLE IS JUST ONE VIEW ELEMENT). • CREATE YOUR OWN VIEW ---EXTENDS • EACH NODE CAN HAVE MULTIPLE ATTRIBUTES • LOOK TO API FOR DETAILS
  • 80. XML INTERFACE • <TEXTVIEW XMLNS:ANDROID="HTTP://SCHEMAS.ANDROID.COM/APK/RES/ANDROID" ANDROID:LAYOUT_WIDTH="FILL_PARENT" ANDROID:LAYOUT_HEIGHT="FILL_PARENT" ANDROID:TEXT="@STRING/HELLO"/> • XMLNS:ANDROID XML NAMESPACE DECLARATION THAT TELLS THE ANDROID TOOLS THAT YOU ARE GOING TO REFER TO COMMON ATTRIBUTES DEFINED IN THE ANDROID NAMESPACE. THE OUTERMOST TAG IN EVERY ANDROID LAYOUT FILE MUST HAVE THIS ATTRIBUTE. • ANDROID:LAYOUT_WIDTH THIS ATTRIBUTE DEFINES HOW MUCH OF THE AVAILABLE WIDTH ON THE SCREEN THIS VIEW SHOULD CONSUME. AS IT'S THE ONLY VIEW SO YOU WANT IT TO TAKE UP THE ENTIRE SCREEN, WHICH IS WHAT A VALUE OF "FILL_PARENT" MEANS. ANDROID:LAYOUT_HEIGHT THIS IS JUST LIKE ANDROID:LAYOUT_WIDTH, EXCEPT THAT IT REFERS TO AVAILABLE SCREEN HEIGHT. • ANDROID:TEXT THIS SETS THE TEXT THAT THE TEXTVIEW SHOULD DISPLAY. IN THIS EXAMPLE, YOU USE A STRING RESOURCE INSTEAD OF A HARD-CODED STRING VALUE. THE HELLO STRING IS DEFINED IN THE RES/VALUES/STRINGS.XML FILE.
  • 81. USING ECLIPSE IDE TO VISUALLY CREATE XML FILE • VISUAL CREATION OF XML FILE • CREATE NEW->OTHER->ANDROID->XML FILE• SELECT FOR LAYOUT TYPE • PLAY WITH IT…. DRAG AND DROP
  • 82. USING ECLIPSE IDE TO VISUALLY CREATE XML FILE • VISUAL CREATION OF XML FILE • CREATE NEW->OTHER->ANDROID->XML FILE• SELECT FOR LAYOUT TYPE • PLAY WITH IT…. DRAG AND DROP
  • 83. VISUALLY CREATING XML INTERFACE • I DRAGGED AND DROPPED AN EDITTEXT VIEW AND A BUTTON. BELOW I SHOW YOU THE CORRESPONDING CODE. RES/LAYOUT/MAIN2.XML <?XML VERSION="1.0" ENCODING="UTF-8"?> <ABSOLUTELAYOUT XMLNS:ANDROID="HTTP://SCHEMAS.ANDROID.COM/APK/RES/ANDROID" ANDROID:ORIENTATION="VERTICAL" ANDROID:LAYOUT_WIDTH="MATCH_PARENT" ANDROID:LAYOUT_HEIGHT="MATCH_PARENT"> <EDITTEXT ANDROID:TEXT="@STRING/HELLO" ANDROID:ID="@+ID/EDITTEXT1" ANDROID:INPUTTYPE="TEXTMULTILINE" ANDROID:LAYOUT_WIDTH="169DP" ANDROID:LAYOUT_HEIGHT="115DP" ANDROID:LAYOUT_X="11DP" ANDROID:LAYOUT_Y="20DP"></EDITTEXT> <BUTTON ANDROID:ID="@+ID/BUTTON1" ANDROID:LAYOUT_WIDTH="WRAP_CONTENT" ANDROID:LAYOUT_HEIGHT="WRAP_CONTENT" ANDROID:TEXT="BUTTON" ANDROID:LAYOUT_X="27DP" ANDROID:LAYOUT_Y="146DP"></BUTTON> </ABSOLUTELAYOUT>
  • 84. BESIDES DRAG AND DROP YOU CAN EDIT THE XML FILE DIRECTLY. LETS DISCUSS SOME OF THE ANDROID XML INTERFACE RELATED TAGS XML INTERFACE TAGS
  • 85. LAYOUT TAGS CONTROL STRUCTURE OF INTERFACE
  • 86. LAYOUT TAGS • DETERMINES HOW THE LAYOUT IS STRUCTURED. • SOME TAGS • LINEARLAYOUT • A LAYOUT THAT ARRANGES ITS CHILDREN IN A SINGLE COLUMN OR A SINGLE ROW. THE DIRECTION OF THE ROW CAN BE SET BY CALLING SETORIENTATION(). YOU CAN ALSO SPECIFY GRAVITY, WHICH SPECIFIES THE ALIGNMENT OF ALL THE CHILD ELEMENTS BY CALLING SETGRAVITY() OR SPECIFY THAT SPECIFIC CHILDREN GROW TO FILL UP ANY REMAINING SPACE IN THE LAYOUT BY SETTING THE WEIGHT MEMBER OF LINEARLAYOUT.LAYOUTPARAMS. THE DEFAULT ORIENTATION IS HORIZONTAL. • ABSOLUTELAYOUT • A LAYOUT THAT LETS YOU SPECIFY EXACT LOCATIONS (X/Y COORDINATES) OF ITS CHILDREN. ABSOLUTE LAYOUTS ARE LESS FLEXIBLE AND HARDER TO MAINTAIN THAN OTHER TYPES OF LAYOUTS WITHOUT ABSOLUTE POSITIONING. • RELATIVELAYOUT • FRAMELAYOUT • TABLELAYOUT
  • 87. LINEARLAYOUT XML TAG • VISUAL CREATION OF XML FILE • XML ATTRIBUTES ATTRIBUTE NAME RELATED METHOD DESCRIPTION ANDROID:BASELINEALIGNED SETBASELINEALIGNED(BOOLEAN) WHEN SET TO FALSE, PREVENTS THE LAYOUT FROM ALIGNING ITS CHILDREN'S BASELINES. ANDROID:BASELINEALIGNEDCHILDINDEX SETBASELINEALIGNEDCHILDINDEX(INT) WHEN A LINEAR LAYOUT IS PART OF ANOTHER LAYOUT THAT IS BASELINE ALIGNED, IT CAN SPECIFY WHICH OF ITS CHILDREN TO BASELINE ALIGN TO (THAT IS, WHICH CHILD TEXTVIEW). ANDROID:GRAVITY SETGRAVITY(INT) SPECIFIES HOW TO PLACE THE CONTENT OF AN OBJECT, BOTH ON THE X- AND Y-AXIS, WITHIN THE OBJECT ITSELF. ANDROID:MEASUREWITHLARGESTCHILD WHEN SET TO TRUE, ALL CHILDREN WITH A WEIGHT WILL BE CONSIDERED HAVING THE MINIMUM SIZE OF THE LARGEST CHILD. ANDROID:ORIENTATION SETORIENTATION(INT) SHOULD THE LAYOUT BE A COLUMN OR A ROW? USE "HORIZONTAL" FOR A ROW, "VERTICAL" FOR A COLUMN. ANDROID:WEIGHTSUM DEFINES THE MAXIMUM WEIGHT SUM.
  • 88. RELATED LAYOUT TAGS CONTROL STRUCTURE OF INTERFACE, BUT COMMONLY A SUB-AREA
  • 89. LISTVIEW <LISTVIEW …..> • A VIEW THAT SHOWS ITEMS IN A VERTICALLY SCROLLING LIST. ATTRIBUTES • ANDROID:DIVIDER DRAWABLE OR COLOR TO DRAW BETWEEN LIST ITEMS. • ANDROID:DIVIDERHEIGHT HEIGHT OF THE DIVIDER. • ANDROID:ENTRIES REFERENCE TO AN ARRAY RESOURCE THAT WILL POPULATE THE LISTVIEW. • ANDROID:FOOTERDIVIDERSENABLED WHEN SET TO FALSE, THE LISTVIEW WILL NOT DRAW THE DIVIDER BEFORE EACH FOOTER VIEW. • ANDROID:HEADERDIVIDERSENABLED WHEN SET TO FALSE, THE LISTVIEW WILL NOT DRAW THE DIVIDER AFTER EACH HEADER VIEW.
  • 90. GALLERY <GALLERY ….> • A VIEW THAT SHOWS ITEMS IN A CENTER-LOCKED, HORIZONTALLY SCROLLING LIST. • THE DEFAULT VALUES FOR THE GALLERY ASSUME YOU WILL BE USING THEME_GALLERYITEMBACKGROUND AS THE BACKGROUND FOR EACH VIEW GIVEN TO THE GALLERY FROM THE ADAPTER. IF YOU ARE NOT DOING THIS, YOU MAY NEED TO ADJUST SOME GALLERY PROPERTIES, SUCH AS THE SPACING. ATTRIBUTES • ANDROID:ANIMATIONDURATION SETANIMATIONDURATION(INT) SETS HOW LONG A TRANSITION ANIMATION SHOULD RUN (IN MILLISECONDS) WHEN LAYOUT HAS CHANGED. • ANDROID:GRAVITY SETGRAVITY(INT) SPECIFIES HOW TO PLACE THE CONTENT OF AN OBJECT, BOTH ON THE X- AND Y-AXIS, WITHIN THE OBJECT ITSELF. • ANDROID:SPACING SETSPACING(INT) • ANDROID:UNSELECTEDALPHA SETUNSELECTEDALPHA(FLOAT) SETS THE ALPHA ON THE ITEMS THAT ARE NOT SELECTED.
  • 91. CODE—SETTING UP GALLERY @OVERRIDE PUBLIC VOID ONCREATE(BUNDLE SAVEDINSTANCESTATE) { SUPER.ONCREATE(SAVEDINSTANCESTATE); SETCONTENTVIEW(R.LAYOUT.MAIN); GALLERY GALLERY = (GALLERY) FINDVIEWBYID(R.ID.GALLERY); GALLERY.SETADAPTER(NEW IMAGEADAPTER(THIS)); GALLERY.SETONITEMCLICKLISTENER(NEW ONITEMCLICKLISTENER() { PUBLIC VOID ONITEMCLICK(ADAPTERVIEW PARENT, VIEW V, INT POSITION, LONG ID) { TOAST.MAKETEXT(HELLOGALLERY.THIS, "" + POSITION, TOAST.LENGTH_SHORT).SHOW(); } }); }
  • 92. VIEWS AND VIEWGROUPS MAKING THE ELEMENTS OF YOUR GUI
  • 93. VIEWS AND VIEWGROUPS • AN ACTIVITY CAN CONTAIN VIEWS AND VIEWGROUPS. • ANDROID.VIEW.VIEW.* = BASE CLASS FOR ALL VIEWS. • EXAMPLE SUB-CLASSES INCLUDE: TEXTVIEW, IMAGEVIEW, ETC. • ANDROID.VIEW.VIEWGROUP = LAYOUT FOR VIEWS IT CONTAINS, SUBCLASSES INCLUDE • ANDROID.WIDGET.LINEARLAYOUT • ANDROID.WIDGET.ABSOLUTELAYOUT • ANDROID.WIDGET.TABLELAYOUT • ANDROID.WIDGET.RELATIVELAYOUT • ANDROID.WIDGET.FRAMELAYOUT • ANDROID.WIDGET.SCROLLLAYOUT
  • 94. LINEARLAYOUT (<LINEARLAYOUT> OR ANDROID.WIDGET.LINEARLAYOUT) • ARRANGES BY SINGLE COLUMN OR ROW. • CHILD VIEWS CAN BE ARRANGED VERTICALLY OR HORIZONTALLY. <?XML VERSION="1.0" ENCODING="UTF-8"?> <LINEARLAYOUT XMLNS:ANDROID="HTTP://SCHEMAS.ANDROID.COM/APK/RES/ANDROID" ANDROID:LAYOUT_WIDTH="FILL_PARENT" ANDROID:LAYOUT_HEIGHT="FILL_PARENT" ANDROID:ORIENTATION="VERTICAL" > <TEXT VIEW ANDROID:LAYOUT_WIDTH=―FILL_PARENT‖ ANDROID:LAYOUT_HEIGHT=―WRAP_CONTENT‖ ANDROID:TEXT=―@STRING/HELLO‖/> </LINEARLAYOUT>
  • 95. LINEAR LAYOUT EXAMPLE <?XML VERSION="1.0" ENCODING="UTF-8"?> <LINEARLAYOUT XMLNS:ANDROID="HTTP://SCHEMAS.ANDROID.COM/APK/RES/ANDROID" ANDROID:LAYOUT_WIDTH="FILL_PARENT" ANDROID:LAYOUT_HEIGHT="FILL_PARENT― ANDROID:ORIENTATION="VERTICAL" > <BUTTON ANDROID:ID="@+ID/BTN_WEBBROWSER" ANDROID:LAYOUT_WIDTH="FILL_PARENT" ANDROID:LAYOUT_HEIGHT="WRAP_CONTENT" ANDROID:TEXT="WEB BROWSER― ANDROID:ONCLICK="ONCLICKWEBBROWSER" /> <BUTTON ANDROID:ID="@+ID/BTN_MAKECALLS" ANDROID:LAYOUT_WIDTH="FILL_PARENT" ANDROID:LAYOUT_HEIGHT="WRAP_CONTENT― ANDROID:TEXT="MAKE CALLS" ANDROID:ONCLICK="ONCLICKMAKECALLS" /> <BUTTON ANDROID:ID="@+ID/BTN_SHOWMAP" ANDROID:LAYOUT_WIDTH="FILL_PARENT" ANDROID:LAYOUT_HEIGHT="WRAP_CONTENT― ANDROID:TEXT="SHOW MAP" ANDROID:ONCLICK="ONCLICKSHOWMAP" /> <BUTTON ANDROID:ID="@+ID/BTN_LAUNCHMYBROWSER" ANDROID:LAYOUT_WIDTH="FILL_PARENT" ANDROID:LAYOUT_HEIGHT="WRAP_CONTENT" ANDROID:TEXT="LAUNCH MY BROWSER" ANDROID:ONCLICK="ONCLICKLAUNCHMYBROWSER" /> </LINEARLAYOUT>
  • 96. LINEARLAYOUT ATTRIBUTES • YOU CAN SET EITHER IN XML OR WITH SET*() METHODS. • I.E. XML ANDROID:ORIENTATION=―VERTICAL‖ CODE (LL IS LINEARLAYOUT INSTANCE) LL.SETORIENTATION(VERTICAL);
  • 97. EACH VIEW OR VIEWGROUP CAN HAVE ITS OWN SET OF ATTRIBUTES…BUT, SOME ARE VERY COMMON Attribute Description layout_width specifies width of View or ViewGroup layout_height specifies height layout_marginTop extra space on top layout_marginBottom extra space on bottom side layout_marginLeft extra space on left side layout_marginRight extra space on right side layout_gravity how child views are positioned layout_weight how much extra space in layout should be allocated to View (only when in LinearLayout or TableView) layout_x x-coordinate layout_y y-coordinate
  • 98. GOAL • UNDERSTAND APPLICATIONS AND THEIR COMPONENTS • CONCEPTS: • ACTIVITY, • SERVICE, • BROADCAST RECEIVER, • CONTENT PROVIDER, • INTENT, • ANDROIDMANIFEST
  • 99. APPLICATIONS • WRITTEN IN JAVA (IT‘S POSSIBLE TO WRITE NATIVE CODE – WILL NOT COVER THAT HERE) • GOOD SEPARATION (AND CORRESPONDING SECURITY) FROM OTHER APPLICATIONS: • EACH APPLICATION RUNS IN ITS OWN PROCESS • EACH PROCESS HAS ITS OWN SEPARATE VM • EACH APPLICATION IS ASSIGNED A UNIQUE LINUX USER ID – BY DEFAULT FILES OF THAT APPLICATION ARE ONLY VISIBLE TO THAT APPLICATION (CAN BE EXPLICITLY EXPORTED)
  • 100. APPLICATION COMPONENTS • ACTIVITIES – VISUAL USER INTERFACE FOCUSED ON A SINGLE THING A USER CAN DO • SERVICES – NO VISUAL INTERFACE – THEY RUN IN THE BACKGROUND • BROADCAST RECEIVERS – RECEIVE AND REACT TO BROADCAST ANNOUNCEMENTS • CONTENT PROVIDERS – ALLOW DATA EXCHANGE BETWEEN APPLICATIONS
  • 101. ACTIVITIES • BASIC COMPONENT OF MOST APPLICATIONS • MOST APPLICATIONS HAVE SEVERAL ACTIVITIES THAT START EACH OTHER AS NEEDED • EACH IS IMPLEMENTED AS A SUBCLASS OF THE BASE ACTIVITY CLASS
  • 102. ACTIVITIES – THE VIEW • EACH ACTIVITY HAS A DEFAULT WINDOW TO DRAW IN (ALTHOUGH IT MAY PROMPT FOR DIALOGS OR NOTIFICATIONS) • THE CONTENT OF THE WINDOW IS A VIEW OR A GROUP OF VIEWS (DERIVED FROM VIEW OR VIEWGROUP) • EXAMPLE OF VIEWS: BUTTONS, TEXT FIELDS, SCROLL BARS, MENU ITEMS, CHECK BOXES, ETC. • VIEW(GROUP) MADE VISIBLE VIA ACTIVITY.SETCONTENTVIEW() METHOD.
  • 103. SERVICES • DOES NOT HAVE A VISUAL INTERFACE • RUNS IN THE BACKGROUND INDEFINITELY • EXAMPLES • NETWORK DOWNLOADS • PLAYING MUSIC • TCP/UDP SERVER • YOU CAN BIND TO A AN EXISTING SERVICE AND CONTROL ITS OPERATION
  • 104. BROADCAST RECEIVERS • RECEIVE AND REACT TO BROADCAST ANNOUNCEMENTS • EXTEND THE CLASS BROADCASTRECEIVER • EXAMPLES OF BROADCASTS: • LOW BATTERY, POWER CONNECTED, SHUTDOWN, TIMEZONE CHANGED, ETC. • OTHER APPLICATIONS CAN INITIATE BROADCASTS
  • 105. CONTENT PROVIDERS • MAKES SOME OF THE APPLICATION DATA AVAILABLE TO OTHER APPLICATIONS • IT‘S THE ONLY WAY TO TRANSFER DATA BETWEEN APPLICATIONS IN ANDROID (NO SHARED FILES, SHARED MEMORY, PIPES, ETC.) • EXTENDS THE CLASS CONTENTPROVIDER; • OTHER APPLICATIONS USE A CONTENTRESOLVER OBJECT TO ACCESS THE DATA PROVIDED VIA A CONTENTPROVIDER
  • 106. INTENTS • AN INTENT IS AN INTENT OBJECT WITH A MESSAGE CONTENT. • ACTIVITIES, SERVICES AND BROADCAST RECEIVERS ARE STARTED BY INTENTS. CONTENTPROVIDERS ARE STARTED BY CONTENTRESOLVERS: • AN ACTIVITY IS STARTED BY CONTEXT.STARTACTIVITY(INTENT INTENT) OR ACTIVITY.STARTACTIVITYFORRESULT(INTENT INTENT, INT REQUESTCODE) • A SERVICE IS STARTED BY CONTEXT.STARTSERVICE(INTENT SERVICE) • AN APPLICATION CAN INITIATE A BROADCAST BY USING AN INTENT IN ANY OF CONTEXT.SENDBROADCAST(INTENT INTENT), CONTEXT.SENDORDEREDBROADCAST(), AND CONTEXT.SENDSTICKYBROADCAST()
  • 107. SHUTTING DOWN COMPONENTS • ACTIVITIES • CAN TERMINATE ITSELF VIA FINISH(); • CAN TERMINATE OTHER ACTIVITIES IT STARTED VIA FINISHACTIVITY(); • SERVICES • CAN TERMINATE VIA STOPSELF(); OR CONTEXT.STOPSERVICE(); • CONTENT PROVIDERS • ARE ONLY ACTIVE WHEN RESPONDING TO CONTENTRESOLVERS • BROADCAST RECEIVERS • ARE ONLY ACTIVE WHEN RESPONDING TO BROADCASTS
  • 108. ANDROID MANIFEST • ITS MAIN PURPOSE IN LIFE IS TO DECLARE THE COMPONENTS TO THE SYSTEM: <?XML VERSION="1.0" ENCODING="UTF-8"?> <MANIFEST . . . > <APPLICATION . . . > <ACTIVITY ANDROID:NAME="COM.EXAMPLE.PROJECT.FRENETICACTIVIT Y" ANDROID:ICON="@DRAWABLE/SMALL_PIC.PNG" ANDROID:LABEL="@STRING/FRENETICLABEL" ... > </ACTIVITY> ... </APPLICATION> </MANIFEST>
  • 109. INTENT FILTERS • DECLARE INTENTS HANDLED BY THE CURRENT APPLICATION Shows in the (IN THE ANDROIDMANIFEST): Launcher and is the main activity to start <?XML VERSION="1.0" ENCODING="UTF-8"?> <MANIFEST . . . > <APPLICATION . . . > <ACTIVITY ANDROID:NAME="COM.EXAMPLE.PROJECT.FRENETICACTIVITY" ANDROID:ICON="@DRAWABLE/SMALL_PIC.PNG" ANDROID:LABEL="@STRING/FRENETICLABEL" ... > <INTENT-FILTER . . . > <ACTION ANDROID:NAME="ANDROID.INTENT.ACTION.MAIN" /> <CATEGORY ANDROID:NAME="ANDROID.INTENT.CATEGORY.LAUNCHER" /> </INTENT-FILTER> <INTENT-FILTER . . . > <ACTION ANDROID:NAME="COM.EXAMPLE.PROJECT.BOUNCE" /> <DATA ANDROID:MIMETYPE="IMAGE/JPEG" /> <CATEGORY ANDROID:NAME="ANDROID.INTENT.CATEGORY.DEFAULT" /> </INTENT-FILTER> </ACTIVITY> ... </APPLICATION> </MANIFEST> Handles JPEG images in some way
  • 110. DATE STORAGE IN ANDROID
  • 111. • ANDROID PROVIDES SEVERAL OPTIONS FOR YOU TO SAVE PERSISTENT APPLICATION DATA. THE SOLUTION YOU CHOOSE DEPENDS ON YOUR SPECIFIC NEEDS, SUCH AS WHETHER THE DATA SHOULD BE PRIVATE TO YOUR APPLICATION OR ACCESSIBLE TO OTHER APPLICATIONS (AND THE USER) AND HOW MUCH SPACE YOUR DATA REQUIRES.
  • 112. YOUR DATA STORAGE OPTIONS ARE THE FOLLOWING: • SHARED PREFERENCES STORE PRIVATE PRIMITIVE DATA IN KEY-VALUE PAIRS. • INTERNAL STORAGE STORE PRIVATE DATA ON THE DEVICE MEMORY. • EXTERNAL STORAGE STORE PUBLIC DATA ON THE SHARED EXTERNAL STORAGE. • SQLITE DATABASES STORE STRUCTURED DATA IN A PRIVATE DATABASE. • NETWORK CONNECTION STORE DATA ON THE WEB WITH YOUR OWN NETWORK SERVER.
  • 113. SHARED PREFERENCES • THE SHAREDPREFERENCES CLASS PROVIDES A GENERAL FRAMEWORK THAT ALLOWS YOU TO SAVE AND RETRIEVE PERSISTENT KEY-VALUE PAIRS OF PRIMITIVE DATA TYPES. YOU CAN USE SHAREDPREFERENCES TO SAVE ANY PRIMITIVE DATA: BOOLEANS, FLOATS, INTS, LONGS, AND STRINGS. THIS DATA WILL PERSIST ACROSS USER SESSIONS (EVEN IF YOUR APPLICATION IS KILLED).
  • 114. INTERNAL STORAGE • YOU CAN SAVE FILES DIRECTLY ON THE DEVICE'S INTERNAL STORAGE. BY DEFAULT, FILES SAVED TO THE INTERNAL STORAGE ARE PRIVATE TO YOUR APPLICATION AND OTHER APPLICATIONS CANNOT ACCESS THEM (NOR CAN THE USER). WHEN THE USER UNINSTALLS YOUR APPLICATION, THESE FILES ARE REMOVED.
  • 115. EXTERNAL STORAGE • EVERY ANDROID-COMPATIBLE DEVICE SUPPORTS A SHARED "EXTERNAL STORAGE" THAT YOU CAN USE TO SAVE FILES. THIS CAN BE A REMOVABLE STORAGE MEDIA (SUCH AS AN SD CARD) OR AN INTERNAL (NON-REMOVABLE) STORAGE. FILES SAVED TO THE EXTERNAL STORAGE ARE WORLD-READABLE AND CAN BE MODIFIED BY THE USER WHEN THEY ENABLE USB MASS STORAGE TO TRANSFER FILES ON A COMPUTER. • CAUTION: EXTERNAL STORAGE CAN BECOME UNAVAILABLE IF THE USER MOUNTS THE EXTERNAL STORAGE ON A COMPUTER OR REMOVES THE MEDIA, AND THERE'S NO SECURITY ENFORCED UPON FILES YOU SAVE TO THE EXTERNAL STORAGE. ALL APPLICATIONS CAN READ AND WRITE FILES PLACED ON THE EXTERNAL STORAGE AND THE USER CAN REMOVE THEM.
  • 116. SQLITE DATABASES • ANDROID PROVIDES FULL SUPPORT FOR SQLITE DATABASES. ANY DATABASES YOU CREATE WILL BE ACCESSIBLE BY NAME TO ANY CLASS IN THE APPLICATION, BUT NOT OUTSIDE THE APPLICATION. • THE RECOMMENDED METHOD TO CREATE A NEW SQLITE DATABASE IS TO CREATE A SUBCLASS OF SQLITEOPENHELPER AND OVERRIDE THE ONCREATE() METHOD, IN WHICH YOU CAN EXECUTE A SQLITE COMMAND TO CREATE TABLES IN THE DATABASE. FOR EXAMPLE:
  • 117. NETWORK CONNECTION • YOU CAN USE THE NETWORK (WHEN IT'S AVAILABLE) TO STORE AND RETRIEVE DATA ON YOUR OWN WEB-BASED SERVICES. TO DO NETWORK OPERATIONS, USE CLASSES IN THE FOLLOWING PACKAGES: • JAVA.NET.* • ANDROID.NET.*
  • 118. SQLLITE AND JAVA
  • 119. SQLLITE • EMBEDDED RDBMS • ACID COMPLIANT ( IN COMPUTER SCIENCE, ACID (ATOMICITY, CONSISTENCY, ISOLATION, DURABILITY) IS A SET OF PROPERTIES THAT GUARANTEE THAT DATABASE TRANSACTIONS ARE PROCESSED RELIABLY. IN THE CONTEXT OF DATABASES, A SINGLE LOGICAL OPERATION ON THE DATA IS CALLED A TRANSACTION. FOR EXAMPLE, A TRANSFER OF FUNDS FROM ONE BANK ACCOUNT TO ANOTHER, EVEN INVOLVING MULTIPLE CHANGES SUCH AS DEBITING ONE ACCOUNT AND CREDITING ANOTHER, IS A SINGLE TRANSACTION.) • SIZE – ABOUT 257 KBYTES • NOT A CLIENT/SERVER ARCHITECTURE • ACCESSED VIA FUNCTION CALLS FROM THE APPLICATION • WRITING (INSERT, UPDATE, DELETE) LOCKS THE DATABASE, QUERIES CAN BE DONE IN PARALLEL
  • 120. SQLLITE • DATASTORE – SINGLE, CROSS PLATFORM FILE (KINDA LIKE AN MS ACCESS DB) • DEFINITIONS • TABLES • INDICIES • DATA
  • 121. SQLITE DATA TYPES • THIS IS QUITE DIFFERENT THAN THE NORMAL SQL DATA TYPES SO PLEASE READ: HTTP://WWW.SQLITE.ORG/DATATYPE3.HTML
  • 122. STORAGE CLASSES • NULL – NULL VALUE • INTEGER - SIGNED INTEGER, STORED IN 1, 2, 3, 4, 6, OR 8 BYTES DEPENDING ON THE MAGNITUDE OF THE VALUE • REAL - A FLOATING POINT VALUE, 8-BYTE IEEE FLOATING POINT NUMBER. • TEXT - TEXT STRING, STORED USING THE DATABASE ENCODING (UTF-8, UTF-16BE OR UTF-16LE). • BLOB. THE VALUE IS A BLOB OF DATA, STORED EXACTLY AS IT WAS INPUT.
  • 123. ANDROID.DATABASE.SQLITE • CONTAINS THE SQLITE DATABASE MANAGEMENT CLASSES THAT AN APPLICATION WOULD USE TO MANAGE ITS OWN PRIVATE DATABASE.
  • 124. ANDROID.DATABASE.SQLITE CLASSES • SQLITECLOSEABLE - AN OBJECT CREATED FROM A SQLITEDATABASE THAT CAN BE CLOSED. • SQLITECURSOR - A CURSOR IMPLEMENTATION THAT EXPOSES RESULTS FROM A QUERY ON A SQLITEDATABASE. • SQLITEDATABASE - EXPOSES METHODS TO MANAGE A SQLITE DATABASE. • SQLITEOPENHELPER - A HELPER CLASS TO MANAGE DATABASE CREATION AND VERSION MANAGEMENT. • SQLITEPROGRAM - A BASE CLASS FOR COMPILED SQLITE PROGRAMS. • SQLITEQUERY - A SQLITE PROGRAM THAT REPRESENTS A QUERY THAT READS THE RESULTING ROWS INTO A CURSORWINDOW. • SQLITEQUERYBUILDER - A CONVENIENCE CLASS THAT HELPS BUILD SQL QUERIES TO BE SENT TO SQLITEDATABASE OBJECTS. • SQLITESTATEMENT - A PRE-COMPILED STATEMENT AGAINST A SQLITEDATABASE THAT CAN BE REUSED.
  • 125. ANDROID.DATABASE.SQLITE.SQLITED ATABASE • CONTAINS THE METHODS FOR: CREATING, OPENING, CLOSING, INSERTING, UPDATING, DELETING AND QUERING AN SQLITE DATABASE • THESE METHODS ARE SIMILAR TO JDBC BUT MORE METHOD ORIENTED THAN WHAT WE SEE WITH JDBC (REMEMBER THERE IS NOT A RDBMS SERVER RUNNING)
  • 126. OPENORCREATEDATABASE( ) • THIS METHOD WILL OPEN AN EXISTING DATABASE OR CREATE ONE IN THE APPLICATION DATA AREA import android.database.sqlite.SQLiteDatabase; SQLiteDatabase myDatabase; myDatabase = openOrCreateDatabase ("my_sqlite_database.db" , SQLiteDatabase.CREATE_IF_NECESSARY , null);
  • 127. SQLITE DATABASE PROPERTIES • IMPORTANT DATABASE CONFIGURATION OPTIONS INCLUDE: VERSION, LOCALE, AND THREAD-SAFE LOCKING. import java.util.Locale; myDatabase.setVersion(1); myDatabase.setLockingEnabled(true); myDatabase.SetLocale(Locale.getDefault());
  • 128. CREATING TABLES • CREATE A STATIC STRING CONTAINING THE SQLITE CREATE STATEMENT, USE THE EXECSQL( ) METHOD TO EXECUTE IT. String createAuthor = "CREAT TABLE authors ( id INTEGER PRIMARY KEY AUTOINCREMENT, fname TEXT, lname TEXT); myDatabase.execSQL(createAuthor);
  • 129. INSERT( ) • LONG INSERT(STRING TABLE, STRING NULLCOLUMNHACK, CONTENTVALUES VALUES) import android.content.ContentValues; ContentValues values = new ContentValues( ); values.put("firstname" , "J.K."); values.put("lastname" , "Rowling"); long newAuthorID = myDatabase.insert("tbl_authors" , "" , values);
  • 130. UPDATE( ) • INT UPDATE(STRING TABLE, CONTENTVALUES VALUES, STRING WHERECLAUSE, STRING[ ] WHEREARGS) public void updateBookTitle(Integer bookId, String newTitle) { ContentValues values = new ContentValues(); values.put("title" , newTitle); myDatabase.update("tbl_books" , values , "id=?" , new String[ ] {bookId.toString() } ); }
  • 131. DELETE( ) • INT DELETE(STRING TABLE, STRING WHERECLAUSE, STRING[] WHEREARGS) public void deleteBook(Integer bookId) { myDatabase.delete("tbl_books" , "id=?" , new String[ ] { bookId.toString( ) } ) ; }
  • 132. ANDROID.DATABASE • HTTP://DEVELOPER.ANDROID.COM/REFERENCE/ANDROID/ DATABASE/PACKAGE-SUMMARY.HTML • CONTAINS CLASSES AND INTERFACES TO EXPLORE DATA RETURNED THROUGH A CONTENT PROVIDER. • THE MAIN THING YOU ARE GOING TO USE HERE IS THE CURSOR INTERFACE TO GET THE DATA FROM THE RESULTSET THAT IS RETURNED BY A QUERY HTTP://DEVELOPER.ANDROID.COM/REFERENCE/ANDROID/DATABASE /CURSOR.HTML
  • 133. QUERIES • METHOD OF SQLITEDATABASE CLASS AND PERFORMS QUERIES ON THE DB AND RETURNS THE RESULTS IN A CURSOR OBJECT • CURSOR C = MDB.QUERY(P1,P2,P3,P4,P5,P6,P7) • P1 ; TABLE NAME (STRING) • P2 ; COLUMNS TO RETURN (STRING ARRAY) • P3 ; WHERE CLAUSE (USE NULL FOR ALL, ?S FOR SELECTION ARGS) • P4 ; SELECTION ARG VALUES FOR ?S OF WHERE CLAUSE • P5 ; GROUP BY ( NULL FOR NONE) (STRING) • P6 ; HAVING (NULL UNLESS GROUP BY REQUIRES ONE) (STRING) • P7 ; ORDER BY (NULL FOR DEFAULT ORDERING)(STRING) • P8 ; LIMIT (NULL FOR NO LIMIT) (STRING)
  • 134. SIMPLE QUERIES • SQL - "SELECT * FROM ABC;" SQLITE - CURSOR C = MDB.QUERY(ABC,NULL,NULL,NULL,NULL,NULL,NULL); • SQL - "SELECT * FROM ABC WHERE C1=5" SQLITE - CURSOR C = MDB.QUERY( ABC,NULL,"C1=?" , NEW STRING[ ] {"5"},NULL,NULL,NULL); • SQL – "SELECT TITLE,ID FROM BOOKS ORDER BY TITLE ASC" SQLITE – STRING COLSTORETURN [ ] {"TITLE","ID"}; STRING SORTORDER = "TITLE ASC"; CURSOR C = MDB.QUERY("BOOKS",COLSTORETURN, NULL,NULL,NULL,NULL,SORTORDER);
  • 135. SENSORS IN ANDROID
  • 136. • MOST ANDROID-POWERED DEVICES HAVE BUILT-IN SENSORS THAT MEASURE MOTION, ORIENTATION, AND VARIOUS ENVIRONMENTAL CONDITIONS. • THESE SENSORS ARE CAPABLE OF PROVIDING RAW DATA WITH HIGH PRECISION AND ACCURACY, AND ARE USEFUL IF YOU WANT TO MONITOR THREEDIMENSIONAL DEVICE MOVEMENT OR POSITIONING, OR YOU WANT TO MONITOR CHANGES IN THE AMBIENT ENVIRONMENT NEAR A DEVICE. • FOR EXAMPLE, A GAME MIGHT TRACK READINGS FROM A DEVICE'S GRAVITY SENSOR TO INFER COMPLEX USER GESTURES AND MOTIONS, SUCH AS TILT, SHAKE, ROTATION, OR SWING. LIKEWISE, A WEATHER APPLICATION MIGHT USE A DEVICE'S TEMPERATURE SENSOR AND HUMIDITY SENSOR TO CALCULATE AND REPORT THE DEWPOINT, OR A TRAVEL APPLICATION MIGHT USE THE GEOMAGNETIC FIELD SENSOR AND ACCELEROMETER TO REPORT A COMPASS BEARING.
  • 137. THE ANDROID PLATFORM SUPPORTS THREE BROAD CATEGORIES OF SENSORS: • MOTION SENSORS THESE SENSORS MEASURE ACCELERATION FORCES AND ROTATIONAL FORCES ALONG THREE AXES. THIS CATEGORY INCLUDES ACCELEROMETERS, GRAVITY SENSORS, GYROSCOPES, AND ROTATIONAL VECTOR SENSORS. • ENVIRONMENTAL SENSORS THESE SENSORS MEASURE VARIOUS ENVIRONMENTAL PARAMETERS, SUCH AS AMBIENT AIR TEMPERATURE AND PRESSURE, ILLUMINATION, AND HUMIDITY. THIS CATEGORY INCLUDES BAROMETERS, PHOTOMETERS, AND THERMOMETERS. • POSITION SENSORS THESE SENSORS MEASURE THE PHYSICAL POSITION OF A
  • 138. DDMS • ANDROID SHIPS WITH A DEBUGGING TOOL CALLED THE DALVIK DEBUG MONITOR SERVER (DDMS), WHICH PROVIDES PORT-FORWARDING SERVICES, SCREEN CAPTURE ON THE DEVICE, THREAD AND HEAP INFORMATION ON THE DEVICE, LOGCAT, PROCESS, AND RADIO STATE INFORMATION, INCOMING CALL AND SMS SPOOFING, LOCATION DATA SPOOFING, AND MORE. THIS PAGE PROVIDES A MODEST DISCUSSION OF DDMS FEATURES; IT IS NOT AN EXHAUSTIVE EXPLORATION OF ALL THE FEATURES AND CAPABILITIES.
  • 139. • ON ANDROID, EVERY APPLICATION RUNS IN ITS OWN PROCESS, EACH OF WHICH RUNS IN ITS OWN VIRTUAL MACHINE (VM). EACH VM EXPOSES A UNIQUE PORT THAT A DEBUGGER CAN ATTACH TO. • WHEN DDMS STARTS, IT CONNECTS TO ADB. WHEN A DEVICE IS CONNECTED, A VM MONITORING SERVICE IS CREATED BETWEEN ADB AND DDMS, WHICH NOTIFIES DDMS WHEN A VM ON THE DEVICE IS STARTED OR TERMINATED. ONCE A VM IS RUNNING, DDMS RETRIEVES THE VM'S PROCESS ID (PID), VIA ADB, AND OPENS A CONNECTION TO THE VM'S DEBUGGER, THROUGH THE ADB DAEMON (ADBD) ON THE DEVICE. DDMS CAN NOW TALK TO THE VM USING A CUSTOM WIRE PROTOCOL. • DDMS ASSIGNS A DEBUGGING PORT TO EACH VM ON THE DEVICE. TYPICALLY, DDMS ASSIGNS PORT 8600 FOR THE FIRST DEBUGGABLE VM, THE NEXT ON 8601, AND SO ON. WHEN A DEBUGGER CONNECTS TO ONE OF THESE PORTS, ALL TRAFFIC IS FORWARDED TO THE DEBUGGER FROM THE ASSOCIATED VM. YOU CAN ONLY ATTACH A SINGLE DEBUGGER TO A SINGLE PORT, BUT DDMS CAN HANDLE MULTIPLE, ATTACHED DEBUGGERS.
  • 140. GOOGLE PLAY MARKET CHECKLIST