android for java developers oscon 2010
play

Android for Java Developers OSCON 2010 Marko Gargenta - PowerPoint PPT Presentation

Android for Java Developers OSCON 2010 Marko Gargenta Marakana About Marko Gargenta Developed Android Bootcamp for Marakana. Trained over 1,000 developers on Android. Clients include


  1. Android ¡for ¡Java ¡ Developers ¡ OSCON ¡2010 ¡ Marko ¡Gargenta ¡ Marakana ¡

  2. About ¡Marko ¡Gargenta ¡ Developed Android Bootcamp for Marakana. Trained over 1,000 developers on Android. Clients include Qualcomm, Sony-Ericsson, Motorola, Texas Instruments, Cisco, Sharp, DoD. Author of upcoming Learning Android by O’Reilly. Spoke at OSCON, ACM, IEEE, SDC. Organizes SFAndroid.org

  3. Agenda ¡ • The ¡Stack ¡ • Android ¡SDK ¡ • Hello ¡World! ¡ • Main ¡Building ¡Blocks ¡ • Android ¡User ¡Interface ¡ • OperaIng ¡System ¡Features ¡ • Debugging ¡ • Summary ¡

  4. ANDROID ¡STACK ¡

  5. The ¡Stack ¡

  6. Linux ¡Kernel ¡ Android runs on Linux. Applications Home Contacts Phone Browser Other Linux provides as well as: Hardware abstraction layer Application Framework Memory management Activity Window Content View Process management Manager Manager Providers System Networking Package Telephony Resource Location Notiication Manager Manager Manager Manager Manager Libraries Users never see Linux sub system Surface Android Runtime Media SQLite Manager Framework Core Libs The adb shell command opens OpenGL FreeType WebKit Delvik Linux shell VM SGL SSL libc Linux Kernel Flash Binder Display Camera Driver Driver Driver Driver Audio Power Keypad WiFi Driver Mgmt Driver Driver

  7. NaIve ¡Libraries ¡ Bionic , a super fast and small Applications license-friendly libc library Home Contacts Phone Browser Other optimized for embedded use Application Framework Surface Manager for composing Activity Window Content View window manager with off-screen Manager Manager Providers System buffering Package Telephony Resource Location Notiication Manager Manager Manager Manager Manager Libraries 2D and 3D graphics hardware Surface Android Runtime Media SQLite support or software simulation Manager Framework Core Libs OpenGL FreeType WebKit Delvik Media codecs offer support for VM SGL SSL libc major audio/video codecs Linux Kernel Flash Binder Display Camera Driver Driver SQLite database Driver Driver Audio Power Keypad WiFi Driver Mgmt Driver Driver WebKit library for fast HTML rendering

  8. Dalvik ¡ Dalvik VM is Google’s implementation of Java VM Optimized for mobile devices Key Dalvik differences: - Register-based versus stack-based VM - Dalvik runs .dex files - More efficient and compact implementation - Different set of Java libraries than SDK

  9. ApplicaIon ¡Framework ¡ The rich set of system services Applications wrapped in an intuitive Java API. Home Contacts Phone Browser Other This ecosystem that developers Application Framework can easily tap into is what makes Activity Window Content View writing apps for Android easy. Manager Manager Providers System Package Telephony Resource Location Notiication Manager Manager Manager Manager Manager Location, web, telephony, WiFi, Libraries Bluetooth, notifications, media, Surface Android Runtime Media SQLite Manager Framework camera, just to name a few. Core Libs OpenGL FreeType WebKit Delvik VM SGL SSL libc Linux Kernel Flash Binder Display Camera Driver Driver Driver Driver Audio Power Keypad WiFi Driver Mgmt Driver Driver

  10. ApplicaIons ¡ Dalvik Executable + Resources = APK Must be signed (but debug key is okay for development) Many markets with different policies

  11. Android ¡and ¡Java ¡ Android Java = Java SE – AWT/Swing + Android API

  12. Android ¡SDK ¡-­‑ ¡What’s ¡in ¡the ¡box ¡ SDK Tools Docs Platforms Data Skins Images Samples Add-ons Google

  13. HELLO ¡WORLD! ¡

  14. Create ¡New ¡Project ¡ Use the Eclipse tool to create a new Android project. Here are some key constructs: Project ¡ Eclipse ¡construct ¡ Target ¡ minimum ¡to ¡run ¡ App ¡name ¡ whatever ¡ Package ¡ Java ¡package ¡ AcIvity ¡ Java ¡class ¡

  15. The ¡Manifest ¡File ¡ <?xml version= "1.0" encoding="utf-8"?> <manifest xmlns:android= "http://schemas.android.com/apk/res/android" package= "com.marakana" android:versionCode= "1" android:versionName= "1.0"> <application android:icon= "@drawable/icon" android:label="@string/app_name"> <activity android:name= ".HelloAndroid" android:label= "@string/app_name"> <intent-filter> <action android:name= "android.intent.action.MAIN" /> <category android:name= "android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> <uses-sdk android:minSdkVersion= "5" /> </manifest>

  16. The ¡Layout ¡Resource ¡ <?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>

  17. The ¡Java ¡File ¡ package com.marakana; import android.app.Activity; import android.os.Bundle; public class HelloAndroid extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } }

  18. Running ¡on ¡Emulator ¡

  19. MAIN ¡BUILDING ¡BLOCKS ¡

  20. AcIviIes ¡ Activity is to an Android Application application what a Another Another Main Activity Activity Activity web page is to a website. Sort of.

  21. AcIvity ¡Lifecycle ¡ Starting Activities have a well- (1) onCreate() (2) onStart() (3) onRestoreInstanceState() defined lifecycle. The (4) onResume() Android OS manages your activity by Running changing its state. (1) onSaveInstanceState() (3) onResume() (2) onStart() (2) onPause() You fill in the blanks. (1) onRestart() onResume() (1) onSaveInstanceState() Paused Stopped (2) onStop() onDestroy() or <process killed> <process killed> Destroyed

  22. Intents ¡ Intents represent Android Application an events or actions. Another Main Activity Intent Activity They are to Intent Android apps what hyperlinks are to Android Application websites. Sort of. Another Main Activity Intent Activity Intents can be implicit or explicit.

  23. Services ¡ Services are code that runs in the background. They can be started and stopped. Services doesn’t have UI.

  24. Service ¡Lifecycle ¡ Service also has a Starting lifecycle, but it’s (1) onCreate() much simpler than (2) onStart() activity’s. onStart() An activity typically Stopped Running starts and stops a service to do some onStop() work for it in the background, such as onDestroy() or play music, check for <process killed> Destroyed new tweets, etc.

  25. Content ¡Providers ¡ Content Providers share Content content with applications Provider across application Content URI boundaries. insert() Examples of built-in update() Content Providers are: delete() Contacts, MediaStore, query() Settings and more.

  26. Broadcast ¡Receivers ¡ An Intent-based publish-subscribe mechanism. Great for listening system events such as SMS messages.

  27. MyTwiVer ¡– ¡A ¡Real ¡World ¡App ¡ Update list MyTwitter Preference Timeline Timeline Activity Activity Activity Receiver Notify of Read/write new status preferences Update ListView Read Prefs Prefs XML Timeline Updates Adapter Status via Updater web service Read Service Prefs Pull timeline from DB Insert Pull timeline updates updates via in DB web service Start at Twitter.com Timeline boot DB Boot Receiver

  28. ANDROID ¡USER ¡INTERFACE ¡

  29. Two ¡UI ¡Approaches ¡ Procedural ¡ Declara?ve ¡ You ¡write ¡Java ¡code ¡ You ¡write ¡XML ¡code ¡ Similar ¡to ¡Swing ¡or ¡AWT ¡ Similar ¡to ¡HTML ¡of ¡a ¡web ¡page ¡ You can mix and match both styles. Declarative is preferred: easier and more tools

  30. XML-­‑Based ¡User ¡Interface ¡ Use WYSIWYG tools to build powerful XML-based UI. Easily customize it from Java. Separate concerns.

  31. Dips ¡and ¡Sps ¡ px ¡ (pixel) ¡ Dots ¡on ¡the ¡screen ¡ in ¡ (inches) ¡ Size ¡as ¡measured ¡by ¡a ¡ruler ¡ mm ¡ (millimeters) ¡ Size ¡as ¡measured ¡by ¡a ¡ruler ¡ pt ¡ (points) ¡ 1/72 ¡of ¡an ¡inch ¡ dp ¡ (density-­‑independent ¡pixel) ¡ Abstract ¡unit. ¡On ¡screen ¡with ¡160dpi, ¡ 1dp=1px ¡ dip ¡ synonym ¡for ¡dp ¡and ¡ocen ¡used ¡by ¡Google ¡ sp ¡ Similar ¡to ¡dp ¡but ¡also ¡scaled ¡by ¡users ¡font ¡ size ¡preference ¡

  32. Views ¡and ¡Layouts ¡ ViewGroup ViewGroup View View View View Layouts contain other Views, or other Layouts.

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend