1 / 48

Android course

Android course. Introduction. dr Milan Vidaković Chair of Informatics Faculty of Technical Sciences University of Novi Sad. Android. Initially: Mobile phone platform Now: embedded devices platform mobile phones tablets multimedia devices AndroidTV/GoogleTV Set Top Boxes (STB) TV

crescent
Download Presentation

Android course

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Android course Introduction dr Milan Vidaković Chair of Informatics Faculty of Technical Sciences University of Novi Sad

  2. Android • Initially: Mobile phone platform • Now: embedded devices platform • mobile phones • tablets • multimedia devices • AndroidTV/GoogleTV • Set Top Boxes (STB) • TV • PC devices version: http://www.android-x86.org/

  3. Android • Purchased and controlled by the Google • Open platform • Operating System is Open Source • SDK is free http://developer.android.com/index.html • Based on the Linux kernel • kernel and drivers in the kernel space • native libraries in the user space • Java libraries link Java applications to the native libraries • applications are executed in the Java VM (Dalvik VM)

  4. Architecture

  5. Linux kernel • Standar Linux kernel with additional drivers • Binder – IPC (Inter Process Communication) • Ashmem – shared memory • Power Management • Logger • Alarm • Low Memory Killer • Kernel Debugger

  6. Native libraries • Bionic Libc • Utility libraries (Webkit, Media Framework, SQLite • Native servers (Surface Manager – SurfaceFlinger, Audio Manager – AudioFlinger • Hardware Abstraction Libraries (Graphics, Camera, Bluetooth, GPS, Radio, WiFi,...)

  7. Application Framework • Java classes and interfaces • support Android (Java) applications • link Android (Java) applications to the native layer LocationManager lm = (LocationManager) Context.getSystemService(Context.LOCATION_SERVICE);

  8. Android OS versions • Versions: • 1.5 – Cupcake (API v3), • 1.6 – Donut (API v4), • 2.0-2.1 – Eclair (API v7), • 2.2 – Froyo (API v8), • 2.3.x – Gingerbread (API v9 - 10), • 3.x.x – Honeycomb (API v11 - 13), • 4.0.x – Ice CreamSandwitch (API v14 - 15) • 4.1.x – Jelly Bean (API v16 - 17), • 5.0 – Key Lime Pie (API v18)

  9. Mobile Phone Devices • A large number of devices • radio (phone), • camera, • compass, • GPS • Bluetooth • Wifi • movement sensors (Gyro)

  10. Special GUI • Main idea is similar to the desktop GUI • Main input device: touch screen • long touch – context menu • move – scroll • fling – animated scroll • multi touch – zoom

  11. Android applications • Written in the Java language • Complex processing is delegated to the native layer via JNI (Java Native Invocation) • One application over the screen • application can have multiple windows (called activities), but each one is in the full screen mode • applications can use other application’s activities (camera, contacts, etc.)

  12. Types of applications • Activity – GUI window (an application must have at least one activity) • Service – background processing • ContentProvider – for sharing data between applications • BroadcastReceiver – receives system-wide messages

  13. Activity Life Cycle

  14. Activity Life Cycle callbacks • onCreate(): invoked when the activity is created. Used for the initialisation. • System can shut down the application from here: No. • Next: onStart(). • onStart(): invoked when the activity becomes visible. • System can shut down the application from here: No. • Next:onResume(). • onResume(): invoked when the activity is ready for the interaction with the userSystem can shut down the application from here: No. • Next: onPause(). • onRestart(): invoked when an activity has been stopped, and then started again (prior to the restart). • System can shut down the application from here: No. • Next: onStart().

  15. Activity Life Cycle callbacks • onPause(): invoked before the system places another activity over this one, or an user pressed the Home key, or screen saver has been activated. Used to save data. If the application resumes later, (after screen saver), onResume() is invoked; if the activity is no longer visible, onStop() is invoked. • System can shut down the application from here: Da. • Next:onResume() or onStop(). • onStop(): invoked when an activity is no longer visible (other activity is now on the screen). If an activity will no longer be used (Back key is pressed, onDestroy() is invoked; if an activity is coming back (after some other activity), onRestart() is invoked. • System can shut down the application from here: Yes. • Next:onRestart() ili onDestroy().

  16. Activity Life Cycle callbacks • onDestroy(): invoked before an activity is destroyed. Invoked if an application is closed, or the system decided to close the application (due to the low resources situation). Cause can be found by invoking isFinishing() method. isFinishing() can be invoked within onPause() method too. • System can shut down the application from here: Yes. • Next: None.

  17. Intents • Intents are messages that are exchanged between activities, services, etc. • There are system intents • There are custom intents

  18. Intents • System matches activities (Activity) with intents (Intent) • Activities declare which intents can activate them • defined in the AndroidManifest.xmlfile • One activity can invoke opther activity by sending Intent • the other activity can be custom activity (created by the programmer), or system activity (contacts, camera, etc.)

  19. Intents

  20. Services • Used for backgroud jobs (music playback, download files, etc.) • It is possible to link application and background service via IPC (InterProcess Communication) implemented as Binder service • list of methods that can be invoked is given in AIDL (Android Interface Definition Language) files

  21. ContentProviders • Used for data sharing between applications • Provide uniform interface for data fetching, creation, removal and modification • Mainly used to share database data between programs • database data is private data and can be accessed by its program • ContentProviders share that private data

  22. BroadcastReceivers • Components which react on broadcasted system messages (battery low, SMS received, etc.) • Broadcast messages are implemented as Intents • BroadcastReceivers usually don’t have their own GUI, but can access status bar notification area

  23. Data storage • Several options: • Preferences • files in the local file system • SQLite database • ContentProvider

  24. APK • Android application is packed in APK file • ZIPfile • Contains executable code, resources and manifest • AndroidManifest.xml

  25. Android SDK • Free Development Kit • Contains: • tools and libraries • adb (Android Debug Bridge) • logcat – interni log Androida • Emulator • Samples in: android-sdk\samples\

  26. Emulator • Emulates both generic and real devices • Emulates different OS versions and API versions • Hardware accelerated (if possible)

  27. adb • Android Debug Bridge • Client-server system • Client is on the host (developer) machine • Server is on the Android device (or emulator) • Provides: • installation of an application to the Android device, • adb install apk_file • copy files from/to Android device, • adb push my_file /sdcard/ • adb pull /sdcard/file . • watch system Log, • adb logcat • work with shell on the Android device, • adb shell • etc.

  28. Eclipse plugin • Integrates Android SDK tools into Eclipse • creates Android projects • provides debugging • visual editor for GUI • displays Log – logcat • takes screen snapshots • dumps memory usage • etc.

  29. Android development cycle • Create activity • override onCreate() method for initialisation • Create GUI • Declare activity in the AndroidManifest.xml file • Install on the device • Start/Debug HelloAndroid

  30. Project structure

  31. Project structure

  32. Create Activity • Activity extends Activity class • Override life cycle callbacs: onCreate(), onStart(), etc.

  33. Create GUI • Two ways: • program • declarative (.xml file) • Declarative is recommended • layout folder, layout.xml • Eclipse plugin generates the R class which holds ids of all resources • whole API works with ids, not with classes and resources!

  34. Create GUI

  35. Create GUI

  36. R class /* AUTO-GENERATED FILE. DO NOT MODIFY. * * This class was automatically generated by the * aapt tool from the resource data it found. It * should not be modified by hand. */ package com.blast; public final class R { public static final class attr { } public static final class drawable { public static final int icon=0x7f020000; } public static final class layout { public static final int main=0x7f030000; } public static final class string { public static final int app_name=0x7f040001; public static final int hello=0x7f040000; } }

  37. Resources • Resources can be: • animation –anim folder • lists of used colors –color folder • multimedia (pictures, animations, etc.) –drawable folder • the rest –raw folder • android.resource://com.blast/raw/famous • xml files which define GUI –layout folder

  38. Resources • Resources can be: • menu description –menu folder • strings –values folder, strings.xml file • i18n • localisation • there can be several xml files with strings • tablestrings.xml, connectionstrings.xml, etc.

  39. Strings

  40. Android manifest • AndroidManifest.xml file • root Java package name • minimal API level • permissions • list of activities, services, BroadcastReceivers, ContentProviders, etc.

  41. Android manifest <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.blast" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="9" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:name=".LayoutExamplesActivity" 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> </manifest>

  42. Installation • Application is placed in the APK file • zip file with defined structure • Each application is digitally signed • no need for the commercial certificate • Eclipse plugin packs and signs the application • can be done manually

  43. Installation • Real device is connected to the developer machine via USB cable, or network • If connected via USB cable: • device needs to have USB debug turned on • If connected via network: • needs to be connected using the following adb command: adb connect x.x.x.x:port • How to check if the device is connected: adb devices

  44. Installation • From the Ecplise – just run the project • Manually: • adb install Application.apk • adb uninstall com.my.package • From the Google Play • APK file is downloaded from the Google server and installed on the device • “safe” • users comments, number of downloads, ranking, etc. • From the SD card • must be enabled in the system settings due to the security reasons

  45. Installation • During installation, the application is copied to the /system/app folder • users do not have priviledges to modifay this folder’s content • Application saves its private data into the /data/data/app folder • The /data folder is the only folder with the full access for the user • The other one folder with the full access for users is the SD card (if exists)

  46. Installation • Each installed application has user priviledges • changing system files and folders is not permitted • Only system processes have the Superuser priviledge (root priviledge) • Rooting the device • subsitute system su application with the hacked one • install the superuser.apk application • consequence: • full access to the device files and applications • rooting error would make the device become the bricked device

  47. Custom firmware • Since the Android OS is open source, it is possible to build and install custom OS into the device • only device drivers are needed in addition to the Android source http://www.cyanogenmod.com/

  48. Developers • Recommended sites for the developers: http://stackoverflow.com http://www.xda-developers.com/

More Related