csce 4013: mobile systems programming
DESCRIPTION
CSCE 4013: Mobile Systems Programming. Nilanjan Banerjee. University of Arkansas Fayetteville, AR [email protected] http:// mpss.csce.uark.edu/mobsys /. Mobile Systems Programming. Few reasons to go MAD with phones…. Smart phones Internet a ccess anywhere Social networking - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/1.jpg)
1
CSCE 4013: Mobile Systems Programming
Nilanjan Banerjee
Mobile Systems Programming
University of ArkansasFayetteville, AR
[email protected]://mpss.csce.uark.edu/mobsys/
![Page 2: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/2.jpg)
2
Few reasons to go MAD with phones…
• Smart phones• Internet access anywhere• Social networking
• Millions of mobile users
• Open standards
![Page 3: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/3.jpg)
3
Introduction to Android
• Open software platform for mobile development• A complete stack—OS, middleware, and Applications• An open Handset Alliance (OHA) project• Powered by the Linux OS• Fast application development in Java• Open source under the Apache 2 license
![Page 4: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/4.jpg)
4
Architecture for Android.
![Page 5: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/5.jpg)
5
Linux kernel
• Works as the HAL (Hardware Abstraction Layer)• Device drivers• Memory management• Process management• Network stack
![Page 6: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/6.jpg)
6
Libraries• C/C++ libraries• Interfaces through Java• Surface manager --- handles the UI Windows• 2D and 3D graphics• Media Codecs, SQLlite, Browser engine
![Page 7: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/7.jpg)
7
Android runtime• Dalvik VM
• Dex file• Compact and efficient than class files
• Core Libraries• Java 5 Std Edition• Collections, I/O --- everything that is in standard Java
![Page 8: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/8.jpg)
8
Application Framework
• API Interface• Activity Manager
• Manages application lifetime
![Page 9: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/9.jpg)
9
Lets jump into a simple Android application
![Page 10: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/10.jpg)
10
Components of an Android application
• Activity• Intent and IntentReceiver• Service• ContentProvider• AndroidManifest (binds all of these together)
![Page 11: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/11.jpg)
11
Activities
• Typically corresponds to one UI screen• But they can be
• Faceless• A floating window• Return a value
• Typically a complex application will have multiple activites• E.g., email application
• Activity 1: log in page• Activity 2: displaying a set of email• Transfer data between activities
• Usually form a bundle and pass it around (we will talk about in detail)
![Page 12: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/12.jpg)
12
Intents
• A description of what you want done… something like a verb• E.g. Intent of a music player is to PLAY
• Intents are of two types – Implicit and Explicit• Explicit
• Application states which Java function to use• Implicit
• System decides for you which intent is best for you
![Page 13: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/13.jpg)
13
Intents
GMail
Contacts
Home
Blogger
ChatClient component makes a request for a specific action
“Pick photo”
Picasa
System picks best component for that actionNew components can use existing functionalityBlogger
Photo Gallery
![Page 14: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/14.jpg)
14
Intent Receivers
• Components that respond to broadcast ‘Intents’• Way to respond to external notification or alarms• Apps can invent and broadcast their own intent• Using intent filters applications can decide which
Intent to respond to
![Page 15: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/15.jpg)
15
Services
• Faceless components that run in the background• E.g., music players, network downloads
![Page 16: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/16.jpg)
16
Content Provider
• Store and retrieves data and makes it accessible to all applications• Resources are specific to your application
• Your application can define a content provider and publish it.
• Android stores content provider in the form of a database• You can access it in your application• Android provides audio, video, images, personal
information• android.provider.Contacts.Phone.
![Page 17: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/17.jpg)
17
Resources
• Utilities that an application uses and “reuses”• Strings, colors, dimensions, style/theme
.
![Page 18: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/18.jpg)
18
Application lifecycle
onCreate()
onStart()
onResume()
Activity running
onPause()
Process is killed
Activity starts
activity comes to foreground
activity comes to background
onStop()
activity is no longer visible
![Page 19: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/19.jpg)
19
Lets look at code again
![Page 20: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/20.jpg)
20
Developing UIs in Android
• Drag and Drop UI development• Using XML + Java • Using Java alone (similar to Swing and AWT).
![Page 21: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/21.jpg)
21
Layouts• Layouts are defined in a layout file (e.g., main.xml)• A layout is made up of Views and ViewGroups.• Every layout file has one root view
<?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" > <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, I am a TextView" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello, I am a Button" /></LinearLayout>
![Page 22: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/22.jpg)
22
Loading an XML resource
• When the application is compiled, each XML layout file is compiled into a View resource.
• This View resource should be loaded in your application code in Activity.onCreate()
public void onCreate(Bundle savedInstance) { super.onCreate(savedInstance); setContentView(R.layout.main);}
![Page 23: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/23.jpg)
23
Views and Widgets
• View is the basis of all UI elements such as Widgets (buttons, TextView, Menus, etc. etc.). It is superclass of all Widget classes
• Each View or ViewGroup object supports a bunch of XML attributes (properties)• ID
• How do I create an instance of the Widget object from my Java code?
android:id = “@+id/my_button” (local resource)android:id = “android:id/zzz” (android resource)
Button myButton = (Button) findViewById(R.id.my_button)
<Button android:id=“@+id/my_button” android:layout_height=“wrap_content” android:layout_width=“wrap_content” android:text=“My Button” />
![Page 24: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/24.jpg)
24
Views and Widgets
• Layout parameters• layout_width, layout_height, layout_margin,
• wrap_content : use space equal to the text inside the view uses
• fill_parent: use as much space as used by the parent view• dip: density independent pixels
• Frame layout• Designed to display one item at a time• You can have multiple widgets but they will be positioned
based on top left of the screen
• Relative layout• Helps greatly when you want to place Views relative to
previous views placed in the actvity• Lets take an example
![Page 25: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/25.jpg)
25
Other interfaces
• onLongClick() (View.onLongClickListener)• When a user touches or holds an item
• onFocusChange() (View.onFocusChangeListener)• Navigates onto or away from an item.
• onKey() (View.onKeyListener)• User is focussed on an item and presses of releases a key
![Page 26: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/26.jpg)
26
Handling UI events
![Page 27: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/27.jpg)
27
Handling UI events
![Page 28: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/28.jpg)
28
Assignment
![Page 29: CSCE 4013: Mobile Systems Programming](https://reader033.vdocuments.net/reader033/viewer/2022042703/56815fff550346895dcefd9a/html5/thumbnails/29.jpg)
29
Next class and todolist
• Continue on application basics for the Android
• Form your group• Pls take a phone if you have already formed a
group
• Set up eclipse with the android SDK and plugin if you have not done so
• Set up Windows Phone 7 IDE