Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Android Programming (CS5248 Fall 2015) Aditya Kulkarni August 26, 2015 *Based on slides from Paresh Mayami.

Similar presentations


Presentation on theme: "Introduction to Android Programming (CS5248 Fall 2015) Aditya Kulkarni August 26, 2015 *Based on slides from Paresh Mayami."— Presentation transcript:

1 Introduction to Android Programming (CS5248 Fall 2015) Aditya Kulkarni (email.aditya.kulkarni@gmail.com) August 26, 2015 *Based on slides from Paresh Mayami (Google Inc.)

2 Contents Introduction Android OS Environment Setup

3 Contents Introduction Android OS Environment Setup Creating and Building Android App Create an Android Project Building and Running Debugging

4 Contents Introduction Android OS Environment Setup Creating and Building Android App Create an Android Project Building and Running Debugging General Topics Android Application Components Misc: Media Recorder, MediaCodec, HTTP Post, MP4Parser

5 Contents Introduction Android OS Environment Setup Creating and Building Android App Create an Android Project Building and Running Debugging General Topics Android Application Components Misc: Media Recorder, MediaCodec, HTTP Post, MP4Parser Sample Application http://developer.android.com/guide/index.html

6 Application Fundamentals Android apps are written in Java

7 Application Fundamentals Android apps are written in Java The Android OS is a multi-user Linux system

8 Application Fundamentals Android apps are written in Java The Android OS is a multi-user Linux system Android app lives in its own security sandbox System assigns each app a unique Linux user ID Each process has its own virtual machine Every application runs in its own Linux process

9 Application Fundamentals Android apps are written in Java The Android OS is a multi-user Linux system Android app lives in its own security sandbox System assigns each app a unique Linux user ID Each process has its own virtual machine Every application runs in its own Linux process The Android system implements the principle of least privilege http://developer.android.com/guide/components/fundamentals.html

10 Environment Setup Four basic steps to get an App running Step 1: Install JDK

11 Environment Setup Four basic steps to get an App running Step 1: Install JDK Step 2: Configure the SDK

12 Environment Setup Four basic steps to get an App running Step 1: Install JDK Step 2: Configure the SDK Step 3: Create your first Android App

13 Environment Setup Four basic steps to get an App running Step 1: Install JDK Step 2: Configure the SDK Step 3: Create your first Android App Step 4: Build and Run your App

14 Step-1: Install JDK

15 JDK Installation JDK and JRE are different! Can download the JDK for your OS at http://java.oracle.com http://java.oracle.com Alternatively, for OS X, Linux: –OS X: Open /Applications/Utilities/Terminal.app Type javac at command line Install Java when prompt appears –Linux: Type sudo apt–get install default–jdk at command line (Debian, Ubuntu) Other distributions: consult the documentation

16 Install! 16

17 Step-2: Configure the SDK

18 SDK Configuration Download Android SDK from http://developer.android.com http://developer.android.com

19 SDK Configuration Download Android SDK from http://developer.android.com http://developer.android.com Or Simplest: Download and install Android Studio bundle (including Android SDK) for your OS

20 Install! 20

21 Step-3: Create your first Android App

22 Your first Android App

23 Long time ago, in a galaxy far, far away …

24 Eclipse IDE- Official IDE for Android development ADT plugin Apache Ant for building projects

25

26

27 … so Google said …

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64 Install

65 Run

66 Recommended: Install Android 2.2, 2.3.3 APIs and 4.x API Do not worry about Intel x86 Atom, MIPS system images Settings Run Android SDK Manager

67 Now you are ready for Android development!

68 Create new Android project

69

70 Create Activity

71

72

73 The Manifest File Identify any user permissions the application requires

74 The Manifest File Identify any user permissions the application requires Declare the minimum API level required by the application

75 The Manifest File Identify any user permissions the application requires Declare the minimum API level required by the application Declare hardware and software features used or required by the application

76 The Manifest File Identify any user permissions the application requires Declare the minimum API level required by the application Declare hardware and software features used or required by the application API libraries the application needs to be linked

77 The Manifest File

78 Step-4: Building & Running your App

79 Building Process Running

80 No Android Device?

81 Install USB Driver !!!

82 Install OEM USB Driver from ASUS website. http://support.asus.com/download/http://support.asus.com/download/ and search by Transformer Update Driver Software from Device Manager Locate USB Driver folder Enable USB Debugging at Transformer USB Driver Installation Update Driver software

83 Enabling USB Debugging

84 Running Sample App

85

86

87 Sample “Hello World” Code

88 Editing Sample Code Add id to main.xml “@+id/helloId”

89 Editing Sample Code Add id to main.xml Edit HelloWorldActivity.java “@+id/helloId”

90 A Sample Code

91 Important points 1.UI Element has an Id 2.Variables in our code link to UI elements 3.Update UI element content from the program 1 2 3

92 App Failure

93 Let us debug the code …

94 Always, look at DDMS !!!

95 Correction

96 Debugging via Dalvik Debug Monitor Service (DDMS) Log.e("Hello, World", "Hello, BJ");

97 Android Application Components

98 Application Components Android Application.apk : Android package

99 Application Components Android Application.apk : Android package Four Application Components Activity Service Content Provider Broadcast Receiver

100 Application Components Android Application.apk : Android package Four Application Components Activity Service Content Provider Broadcast Receiver Communication among components except Content Provider Intent

101 Activity Activity LifecycleImplement Lifecycle Callbacks

102 Activity Hierarchical View Architecture ViewGroup (Layout) View ViewGroup (Layout) View … View ViewGroup …

103 Activity Hierarchical View Architecture ViewGroup (Layout) View ViewGroup (Layout) View … View ViewGroup … Do not forget to declare Activity in the Manifest

104 Activity Start an Activity Start an Activity for a Result Caller Activity Callee Activity finish

105 Activities and Stack

106 Services A service is a component that runs in the background to perform long-running operations

107 Services A service is a component that runs in the background to perform long-running operations A service does not provide a user interface

108 Services A service is a component that runs in the background to perform long-running operations A service does not provide a user interface Another component, such as an activity, can start the service and let it run or bind to it in order to interact with it

109 Services A service is a component that runs in the background to perform long-running operations A service does not provide a user interface Another component, such as an activity, can start the service and let it run or bind to it in order to interact with it e.g a service might play music in the background while the user is in a different app

110 Broadcast Receivers A broadcast receiver is a component that responds to system-wide broadcast announcements

111 Broadcast Receivers A broadcast receiver is a component that responds to system-wide broadcast announcements Apps can also initiate broadcasts

112 Broadcast Receivers A broadcast receiver is a component that responds to system-wide broadcast announcements Apps can also initiate broadcasts Although broadcast receivers don't display a UI, they may create a status bar notification to alert the user when a broadcast event occurs

113 Content Providers A content provider manages a shared set of app data

114 Content Providers A content provider manages a shared set of app data Through the content provider, other apps can query or even modify the data

115 Content Providers A content provider manages a shared set of app data Through the content provider, other apps can query or even modify the data Any app with the proper permissions can query part of the content provider

116 Intent An intent is an abstract description of an operation to be performed

117 Intent An intent is an abstract description of an operation to be performed It can be used with startActivity to launch an ActivitystartActivity Activity

118 Intent An intent is an abstract description of an operation to be performed It can be used with startActivity to launch an ActivitystartActivity Activity broadcastIntent to send it to any interested BroadcastReceiver componentsbroadcastIntent BroadcastReceiver

119 Intent An intent is an abstract description of an operation to be performed It can be used with startActivity to launch an ActivitystartActivity Activity broadcastIntent to send it to any interested BroadcastReceiver componentsbroadcastIntent BroadcastReceiver startService(Intent) or bindService(Intent, ServiceConnection, int) to communicate with a background ServicestartService(Intent)bindService(Intent, ServiceConnection, int)Service

120 UI – Declaring Layout Initiated when called setContentView() on onCreate()

121 UI – Declaring Layout Initiated when called setContentView() on onCreate() Use Visual Layout Editor for initial layout design

122 UI – Declaring Layout Initiated when called setContentView() on onCreate() Use Visual Layout Editor for initial layout design Edit XML file extensively

123 UI – Handling UI Events onClick, onLongClick, onKey, onTouch, …

124 Thread UI Thread “Main” thread per application is responsible for interacting with UI components

125 Thread UI Thread “Main” thread per application is responsible for interacting with UI components “Application Not Responding” problem If UI thread is blocked more than several seconds, ANR dialog appears Do not block the UI thread Do not access UI components outside UI thread

126 Thread UI Thread “Main” thread per application is responsible for interacting with UI components “Application Not Responding” problem If UI thread is blocked more than several seconds, ANR dialog appears Do not block the UI thread Do not access UI components outside UI thread modify

127 Use AsyncTask, Instead

128 Misc - Media Recorder Modify CameraPreview to see the video during recording

129 Misc – Media Codec To access low-level media codecs, i.e. encoder/decoder components

130 Misc - HTTP Post Use HttpClient and HttpPost Use “multi-part/form-data” to encapsulate segment Do not excessively use memory

131 Misc – Permission Issue Add following permissions to the Manifest file

132 Sample Implementation MainActivity CaptureActivity Upload Service PlayerActivity Option menuContext menu Capture Capture Button Click Play click Background Upload

133 Misc - Integration with MP4Parser Adding a jar file Create its jar file Add jar file to the app Build Path > Configure Build Path > Libraries > Add JARs If you include source files directly, Put Isoparser-default.properties to assets folder Change getResourceAsStream(“isoparser- default.properties”) in PropertyBoxParserImpl to “/assets/isoparser-default.properties” https://code.google.com/p/mp4parser/ https://github.com/sannies/mp4parser

134 Final Comment: Use ApiDemo !!!

135 General References How to work with Android GUI layouts https://www.youtube.com/watch?v=xn9KYnwIoBE https://www.youtube.com/watch?v=xn9KYnwIoBE Building and running your app http://developer.android.com/tools/building/building-eclipse.html http://developer.android.com/tools/building/building-eclipse.html Deployment of the.apk file http://stackoverflow.com/questions/3480201/how-do-you-install-an- apk-file-in-the-android-emulator http://stackoverflow.com/questions/3480201/how-do-you-install-an- apk-file-in-the-android-emulator Find the hidden developer option http://www.cnet.com/how- to/restore-the-developer-options-menu-in-android-4-2/http://www.cnet.com/how- to/restore-the-developer-options-menu-in-android-4-2/ Rotation lock/unlock http://www.howtogeek.com/howto/26715/how- to-make-your-android-phone-stop-rotating-the-screen-when- you%E2%80%99re-reading-sideways/ http://www.howtogeek.com/howto/26715/how- to-make-your-android-phone-stop-rotating-the-screen-when- you%E2%80%99re-reading-sideways/ Video tutorials http://www.youtube.com/watch?v=5RHtKIo_KDIhttp://www.youtube.com/watch?v=5RHtKIo_KDI Load/Open an existing package (e.g., the provided ClassExamples) into your eclipse File --> Import... --> General-Tab --> Existing Projects into Workspace (and click Next) Select root Directory: click Browse: select the folder the include the AndroidManifest.xml or project.properties files. Click finish

136 Thank You! Any questions


Download ppt "Introduction to Android Programming (CS5248 Fall 2015) Aditya Kulkarni August 26, 2015 *Based on slides from Paresh Mayami."

Similar presentations


Ads by Google